sacOO7 / SocketclusterClientDotNet

C# client for socketcluster framework in node.js

Home Page:http://socketcluster.io/#!/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

connect error when build to ios/android using unity game engine.

nguyenhaian opened this issue · comments

I write a small code to test connectivity. It works well in unity editor.
But when I build project to ios/android, there are some errors. Could anyone help me?

// Use this for initialization
	void Start ()
	{

		//Create a socket instance
		string url = "ws://localhost:8000/socketcluster/";
		var socket = new Socket (url);
		socket.setReconnectStrategy (null);
		socket.setListerner (new SocketEventListener ());
		socket.setAuthToken ("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0eXBlIjoiYmFzZSIsImF1dGhpZCI6IjU4OWRhMWM2YTY0Zjg0MGVkYTJlZDkwNCIsInVzZXJpZCI6IjU4OWRhMWM2YTY0Zjg0MGVkYTJlZDkwMyIsImlhdCI6MTQ4NzE1OTU5OCwiZXhwIjoxNDg3MjQ1OTk4fQ.GOHzJxF-zTfdfUvkU32EovrSimfjW5KxY7NA9YwKA4A");

		socket.on (SERVICE_PACKAGE, (eventName, package) => {
			Debug.Log ("got message " + package + " from event " + eventName);
			Debug.Log ("typeof data " + package.GetType ());

			if (package is JArray) {
				Debug.Log ("package is JArray");

				JArray datas = (JArray)package;
				Debug.Log (datas.Count);
				Debug.Log (datas [0] ["evt"]);
			}
			if (package is JObject) {
				Debug.Log ("package is JObject");

				JObject data = (JObject)package;
				Debug.Log (data ["evt"]);
			}

		});
		Debug.Log ("start connecting");
		socket.connect ();
	}

ios log:

start connecting
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
Newtonsoft.Json.Utilities.CollectionWrapper`1:System.Collections.IList.get_IsFixedSize()
UnityEngine.Debug:Log(Object)
SCClient:Start()
 
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)

NotSupportedException: /Users/builduser/buildslave/unity/build/Tools/il2cpp/il2cpp/libil2cpp/icalls/mscorlib/System.Reflection.Emit/DynamicMethod.cpp(25) : Unsupported internal call for IL2CPP:DynamicMethod::destroy_dynamic_method - System.Reflection.Emit is not supported.
  at System.Reflection.Emit.DynamicMethod.destroy_dynamic_method (System.Reflection.Emit.DynamicMethod m) [0x00000] in <filename unknown>:0 
  at System.Reflection.Emit.DynamicMethod.Finalize () [0x00000] in <filename unknown>:0 
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Debug:LogWarning(Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogWarning(Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.UnhandledExceptionHandler:PrintException(String, Exception)
UnityEngine.UnhandledExceptionHandler:HandleUnhandledException(Object, UnhandledExceptionEventArgs)
System.UnhandledExceptionEventHandler:Invoke(Object, UnhandledExceptionEventArgs)
 
(Filename: currently not available on il2cpp Line: -1)

NotSupportedException: /Users/builduser/buildslave/unity/build/Tools/il2cpp/il2cpp/libil2cpp/icalls/mscorlib/System.Reflection.Emit/DynamicMethod.cpp(20) : Unsupported internal call for IL2CPP:DynamicMethod::create_dynamic_method - System.Reflection.Emit is not supported.
  at System.Reflection.Emit.DynamicMethod.create_dynamic_method (System.Reflection.Emit.DynamicMethod m) [0x00000] in <filename unknown>:0 
  at System.Reflection.Emit.DynamicMethod.CreateDynMethod () [0x00000] in <filename unknown>:0 
  at System.Reflection.Emit.DynamicMethod.CreateDelegate (System.Type delegateType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Utilities.DynamicReflectionDelegateFactory.CreateDefaultConstructor[T] (System.Type type) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.DefaultContractResolver.GetDefaultCreator (System.Type createdType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract (Newtonsoft.Json.Serialization.JsonContract contract) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateDictionaryContract (System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.DefaultContractResolver.CanConvertToString (System.Type type) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract (System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.DefaultContractResolver.GetSerializableMembers (System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract (System.Type type) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, Boolean checkAdditionalContent) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetContractSafe (System.Object value) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.JsonSerializer.SerializeInternal (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.JsonSerializer.SerializeInternal (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.JsonSerializer.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.JsonConvert.SerializeObjectInternal (System.Object value, System.Type type, Newtonsoft.Json.JsonSerializer jsonSerializer) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value, System.Type type, Formatting formatting, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value, Formatting formatting, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value, Formatting formatting) [0x00000] in <filename unknown>:0 
  at ScClient.Socket.OnSocketOpened (System.Object sender, System.EventArgs e) [0x00000] in <filename unknown>:0 
  at System.EventHandler.Invoke (System.Object sender, System.EventArgs e) [0x00000] in <filename unknown>:0 
  at WebSocket4Net.WebSocket.OnHandshaked () [0x00000] in <filename unknown>:0 
  at System.Collections.ObjectModel.Collection`1[T].ClearItems () [0x00000] in <filename unknown>:0 
  at WebSocket4Net.Command.Handshake.ExecuteCommand (WebSocket4Net.WebSocket session, WebSocket4Net.WebSocketCommandInfo commandInfo) [0x00000] in <filename unknown>:0 
  at WebSocket4Net.WebSocket.add_Closed (System.EventHandler value) [0x00000] in <filename unknown>:0 
  at WebSocket4Net.WebSocket.ExecuteCommand (WebSocket4Net.WebSocketCommandInfo commandInfo) [0x00000] in <filename unknown>:0 
  at WebSocket4Net.WebSocket.OnDataReceived (System.Byte[] data, Int32 offset, Int32 length) [0x00000] in <filename unknown>:0 
  at WebSocket4Net.WebSocket.client_DataReceived (System.Object sender, SuperSocket.ClientEngine.DataEventArgs e) [0x00000] in <filename unknown>:0 
  at System.EventHandler`1[TEventArgs].Invoke (System.Object sender, .TEventArgs e) [0x00000] in <filename unknown>:0 
  at SuperSocket.ClientEngine.ClientSession.OnDataReceived (System.Byte[] data, Int32 offset, Int32 length) [0x00000] in <filename unknown>:0 
  at Mono.Security.Cryptography.MD4..ctor () [0x00000] in <filename unknown>:0 
  at SuperSocket.ClientEngine.AsyncTcpSession.ProcessReceive (System.Net.Sockets.SocketAsyncEventArgs e) [0x00000] in <filename unknown>:0 
  at SuperSocket.ClientEngine.AsyncTcpSession.SocketEventArgsCompleted (System.Object sender, System.Net.Sockets.SocketAsyncEventArgs e) [0x00000] in <filename unknown>:0 
  at System.EventHandler`1[TEventArgs].Invoke (System.Object sender, .TEventArgs e) [0x00000] in <filename unknown>:0 
  at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted (System.Net.Sockets.SocketAsyncEventArgs e) [0x00000] in <filename unknown>:0 
  at Sample.Proxy.ProxyConnectorBase.StartSend (System.Net.Sockets.Socket socket, System.Net.Sockets.SocketAsyncEventArgs e) [0x00000] in <filename unknown>:0 
  at System.Net.Sockets.SocketAsyncEventArgs.ReceiveCallback () [0x00000] in <filename unknown>:0 
  at System.Threading.ThreadStart.Invoke () [0x00000] in <filename unknown>:0 
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Debug:LogWarning(Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogWarning(Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.UnhandledExceptionHandler:PrintException(String, Exception)
UnityEngine.UnhandledExceptionHandler:HandleUnhandledException(Object, UnhandledExceptionEventArgs)
System.UnhandledExceptionEventHandler:Invoke(Object, UnhandledExceptionEventArgs)

My socketcluster server got a warning when ios app runs.

1487214567638 - Origin: Worker (PID 56065)
   [Warning] SocketProtocolError: Did not receive #handshake from client before timeout
    at Emitter.SCSocket._onSCClose (/Users/annguyen/Documents/workspace/node/sc1/server/node_modules/socketcluster/node_modules/socketcluster-server/sc
socket.js:206:17)
    at Emitter.SCSocket.disconnect (/Users/annguyen/Documents/workspace/node/sc1/server/node_modules/socketcluster/node_modules/socketcluster-server/sc
socket.js:226:10)
    at EventEmitter.SCServer._handleHandshakeTimeout (/Users/annguyen/Documents/workspace/node/sc1/server/node_modules/socketcluster/node_modules/socke
tcluster-server/scserver.js:184:12)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)
    at Timer.listOnTimeout (timers.js:207:5)

Android app log:

02-16 10:13:06.923: I/Unity(22341): start connecting
02-16 10:13:06.923: I/Unity(22341):  
02-16 10:13:06.923: I/Unity(22341): (Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
02-16 10:13:07.033: I/Unity(22341): on connect error got called
02-16 10:13:07.033: I/Unity(22341):  
02-16 10:13:07.033: I/Unity(22341): (Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
02-16 10:13:07.033: I/Unity(22341): SuperSocket.ClientEngine.ErrorEventArgs
02-16 10:13:07.033: I/Unity(22341):  
02-16 10:13:07.033: I/Unity(22341): (Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
02-16 10:13:07.033: I/Unity(22341): disconnected got called
02-16 10:13:07.033: I/Unity(22341):  
02-16 10:13:07.033: I/Unity(22341): (Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)

There is no log on my socket cluster server when my android app runs.

update: I am using unity free edition version 5.5.1f1.

ios app's logs above are fired on a simulator, when I build to a real device, app's logs are the same android app's logs.

I think as far as android and ios is considered, client supports xamarin platform. I haven't tried building code using unity yet. Maybe you can search for error on internet. If it is working in unity editor, then it should work on android and ios too. It will be helpful if you can provide me with line numbers of error logs.

update: It works on android and ios, the problem is I forgot to change server IP address from 127.0.0.1 to my computer's LAN IP.
There is one thing to note that JsonConvert.SerializeObject() function does not work with ios, so I have to use another JSON library, I didn't found the good one. I'm using SimpleJSON for now which is very easy to use but can't serialize 'object' type.

You can close this issue now.

Why it doesn't work in ios? can you give me type of error it is producing right now?

It is because of Newtonsoft.Json library. I use MiniJSON instead, and it works fine.

NotSupportedException: /Users/builduser/buildslave/unity/build/Tools/il2cpp/il2cpp/libil2cpp/icalls/mscorlib/System.Reflection.Emit/DynamicMethod.cpp(20) : Unsupported internal call for IL2CPP:DynamicMethod::create_dynamic_method - System.Reflection.Emit is not supported.
  at System.Reflection.Emit.DynamicMethod.create_dynamic_method (System.Reflection.Emit.DynamicMethod m) [0x00000] in <filename unknown>:0 
  at System.Reflection.Emit.DynamicMethod.CreateDynMethod () [0x00000] in <filename unknown>:0 
  at System.Reflection.Emit.DynamicMethod.CreateDelegate (System.Type delegateType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Utilities.DynamicReflectionDelegateFactory.CreateDefaultConstructor[T] (System.Type type) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.DefaultContractResolver.GetDefaultCreator (System.Type createdType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract (Newtonsoft.Json.Serialization.JsonContract contract) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateDictionaryContract (System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.DefaultContractResolver.CanConvertToString (System.Type type) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract (System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.DefaultContractResolver.GetSerializableMembers (System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract (System.Type type) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, Boolean checkAdditionalContent) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetContractSafe (System.Object value) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.JsonSerializer.SerializeInternal (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.JsonSerializer.SerializeInternal (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.JsonSerializer.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.JsonConvert.SerializeObjectInternal (System.Object value, System.Type type, Newtonsoft.Json.JsonSerializer jsonSerializer) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value, System.Type type, Formatting formatting, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value, Formatting formatting, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value, Formatting formatting) [0x00000] in <filename unknown>:0

You can look at the handshake event:

var authobject = new Dictionary<string, object> {
	{ "event", "#handshake" },
	 {
		"data",
		new Dictionary<string,object>{ {
			"authToken",
			AuthToken
			} }
	},
	 {
		"cid",
		Interlocked.Increment (ref counter)
	}
};
// var json = JsonConvert.SerializeObject(authobject, Formatting.Indented); // -> ERROR ON iOS
// var json = Json.Serialize (authobject); // WORK

Oh, good. It's nice you were able to understand and edit the code. I will be closing this issue for now.

Hey, do you have account on gitter? If any further problem persist for unity developers who are using this client, I can redirect them to you.

yes. My gitter account is nguyenhaian.