Closed col000r closed 4 years ago
ah, it's working, but the example didn't really do much. I updated it do more or less the same thing as the browser-example:
`using System; using System.Collections; using System.Collections.Generic; using Socket.Newtonsoft.Json.Linq; using UnityEngine; using Socket.Quobject.SocketIoClientDotNet.Client;
public class TestObject : MonoBehaviour {
private QSocket m_Socket;
private string m_Chat;
private string m_Input;
void Start() {
m_Socket = IO.Socket ("http://localhost:3000" );
m_Socket.On (QSocket.EVENT_CONNECT, () => {
Debug.Log( "Connected" );
m_Socket.Emit ("chat", "test");
});
m_Socket.On ("chat", (data) => {
JObject jObject = data as JObject;
Debug.Log(jObject["msg"]);
m_Chat += Environment.NewLine + "user#" + jObject["id"] + ": " + jObject["msg"];
});
}
private void OnGUI() {
GUILayout.Label( m_Chat );
m_Input = GUILayout.TextField( m_Input );
if( GUILayout.Button( "Send" ) ) {
m_Socket.Emit( "chat", m_Input );
m_Input = "";
}
}
private void OnDestroy() {
m_Socket.Disconnect ();
}
} `
But I still have a problem. For some reason the Unity example reconnects as a new user every ~half minute. Guess I need to do some googling...
hi coll000r! I'll check it out and update the example. Thank you.
I'm running the node.js server and can chat between 2 browsers, but if I run a scene with TestObject in it I get no logs. Also no errors. Am I missing something or is this no longer working in Unity 2019.4?