sta / websocket-sharp

A C# implementation of the WebSocket protocol client and server
http://sta.github.io/websocket-sharp
MIT License
5.68k stars 1.65k forks source link

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

Open marcomarchesi opened 8 years ago

marcomarchesi commented 8 years ago

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?

jespertheend commented 8 years ago

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.

slwsnd commented 8 years ago

try ws.ConnectAsync();

jespertheend commented 8 years ago

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.

daef commented 7 years ago

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...

SunnyVZ777 commented 6 years ago

get the same problem

goorkamateusz commented 1 year ago

It happens sometimes

tichise commented 5 months ago

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