websocket-sharp icon indicating copy to clipboard operation
websocket-sharp copied to clipboard

Unity freezes when I try to connect to the web socket server

Open marcomarchesi opened this issue 9 years ago • 7 comments

I've just started working with websocket-sharp and Unity, I created client and server applications to test it in the same machine. Everything works fine using localhost as local address. Then, I tried to run the server and the client from different machines. Client calls the server with ws://192.168.1.x:8080/something but once I try to play the client from the Unity Editor or from the built app, it freezes for 10-20 seconds but it cannot connect. Currently I'm running the server on a Windows machine and the client on a MacbookPro. If I try to use explicitly an IP address in the same machine for both client and server apps, but I cannot connect. Any ideas?

marcomarchesi avatar Aug 13 '16 18:08 marcomarchesi

I'm having the same issue, but only when the server is turned off. It would be nice to be able to manually set the timeout for closed sockets. Am I missing something? ws.WaitTime = TimeSpan.FromSeconds(1); doesn't seem to do the trick.

jespertheend avatar Sep 06 '16 22:09 jespertheend

try ws.ConnectAsync();

slwsnd avatar Sep 11 '16 10:09 slwsnd

Oh wow, not sure how I missed that. Either way I added my own implementation in #293 because I wanted more control on how long it would wait for a connection.

jespertheend avatar Sep 11 '16 11:09 jespertheend

I already use .ConnectAsync() in unity, still can't change the default timeout...

public IEnumerator ConnectRoutine(string endpoint) {
   ws = new WebSocket(endpoint);
#if DEBUG
   ws.Log.Level = LogLevel.Info;
   ws.Log.File = "ws.log";
#endif
   ws.OnOpen += Ws_OnOpen; // sets isConnected
   ws.OnMessage += Ws_OnMessage;
   ws.OnError += Ws_OnError;
   ws.ConnectAsync();
   while (!isConnected)
      yield return null;
}

I really like @jespertheend 's PR https://github.com/sta/websocket-sharp/pull/293 thou...

daef avatar Jul 11 '17 13:07 daef

get the same problem

SunnyVZ777 avatar Mar 28 '18 05:03 SunnyVZ777

It happens sometimes

goorkamateusz avatar Jan 23 '23 16:01 goorkamateusz

I came to this issue because a similar phenomenon was reproduced.

tichise avatar Mar 30 '24 03:03 tichise