-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unity 4.3.1f1 and websocket-sharp freeze Unity Editor. #35
Comments
Could you try the following? using UnityEngine;
using System.Collections;
using System;
using System.Threading;
using WebSocketSharp;
public class NewBehaviourScript : MonoBehaviour {
WebSocket ws;
void Start () {
ws = new WebSocket ("ws://localhost:8080");
print ("Open socket: " + ws.ReadyState);
print ("Websocket Alive: " + ws.IsAlive);
ws.OnMessage += (sender, e) => {
print ("From srv: " + e.Data);
};
ws.OnOpen += (sender, e) => {
print ("WebSocket-> Open:");
print ("Open socket-> OnOpen: " + ws.ReadyState);
};
ws.OnError += (sender, e) => {
print ("WebSocket-> Error: " + e.Message);
print ("Open socket-> OnError: " + ws.ReadyState);
};
ws.OnClose += (sender, e) => {
print ("WebSocket-> Close-code: " + e.Code);
print ("WebSocket-> Close-reason: " + e.Reason);
print ("Open socket-> OnClose: " + ws.ReadyState);
};
ws.Connect ();
}
void OnDestroy () {
if (ws != null && ws.ReadyState == WebSocketState.Open)
ws.Close ();
}
} And, is the server running? |
Copy & paste your code, and copy websocket-sharp.dll to Assets/Plugins. Run Unity Editor, and editor freeze. Kill process Unity editor, and delete websocket-sharp.dll from Assets/Plugins. Run Unity editor, not freeze, err message: Assets/NewBehaviourScript.cs(8,7): error CS0246: The type or namespace name `WebSocketSharp' could not be found. Are you missing a using directive or an assembly reference?
server not running. add: run server, node.js
and run Unity editor. Copy websocket-sharp.dll, and run project. Unity freeze. |
Hmm,,,
Do you mean 'Copy & paste' has been done without Unity Editor? I don't know your situation correctly, so could you try the following steps?
Do you get something error so far? |
problem disappeared |
I can start the game, and all works fine. But than when I start again, Unity crashes. |
Use method Awake instead of Start |
I have a problem which might be related. In the Unity editor when the server I want to connect to is down, and I stop the player while trying to connect and then start the player again the editor will freeze. However, when I stop the player (while trying to connect) and wait till the connect request is timed out (which I have modified to be just 10 seconds so I don't have to wait the whole default 90secs) the editor will not freeze when I start it again. I am using a self build websocket dll. My code: void Awake() {
ws = new WebSocket (Server);
s.OnMessage += onMessage;
ws.OnOpen += onConnect;
ws.OnError += onError;
ws.OnClose += onClose;
ws.ConnectAsync ();
} void OnApplicationQuit() {
ws.OnMessage -= onMessage;
ws.OnOpen -= onConnect;
ws.OnError -= onError;
ws.OnClose -= onClose;
if (ws != null && ws.ReadyState == WebSocketState.Open) ws.CloseAsync ();
} When I don't remove the event handlers they still fire even though I already have stopped the editor so it seems to me that the websocket process is still running after I have stopped the Unity editor. How can I force Unity to kill the process when it is still trying to connect to the server? Like I said, not a big problem since the server should always be running anyways and 10 seconds isn't that long to wait, but I have the feeling that I am missing something here. |
@Marreck Hello there, To replace with the following, in the OnApplicationQuit method: void OnApplicationQuit() {
...
if (ws != null) ws.Close ();
} Does the above make a difference? (It might make you wait.) I guess to use that async close method is not good for your case. |
Hi, Thanks for your help! With that modification when I pause the editor, it hangs until the connect attempt times out (In my case max 10 seconds instead of the default 90 seconds as set in WebSocket.cs). This kinda solves this problem since you can't press play while the editor hangs and thus can't crash by attempting to reconnect while a previous connection attempt is still happening :). It seems a bit of a weird solution though. Isn't there a way to abort any ongoing connection attempts? |
I'm working on a separate library and I'm having the same issue. Has anyone managed to find a way to fix this? |
Self build websocket-sharp, and add dll (Assets/Plugins). And Unity Editor freeze.
using UnityEngine;
using System.Collections;
using System;
using System.Threading;
using WebSocketSharp;
public class NewBehaviourScript : MonoBehaviour {
}
The text was updated successfully, but these errors were encountered: