endel / NativeWebSocket

🔌 WebSocket client for Unity - with no external dependencies (WebGL, Native, Android, iOS, UWP)
Other
1.13k stars 155 forks source link

Connect to server built with flask-socketio #37

Closed Kyle0936 closed 3 years ago

Kyle0936 commented 3 years ago

Hi there,

Sorry that this question might be stupid but I just started to get in touch with all the networking stuff. I'm wondering if it's possible to use this package to connect to a server built with flask-socketio.

I was testing on my mac and I picked localhost:8765 on the server side and tried to connect it with websocket = new WebSocket("ws://localhost:8765"); but it reported an error:

Error! Unable to connect to the remote server UnityEngine.Debug:Log(Object) <>c:b__1_1(String) (at Assets/Scripts/util/Connection.cs:27) NativeWebSocket.d__26:MoveNext() (at Library/PackageCache/com.endel.nativewebsocket@90f55f370a/WebSocket/WebSocket.cs:477) UnityEngine.UnitySynchronizationContext:ExecuteTasks() (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/UnitySynchronizationContext.cs:107)

Thanks in advance!

endel commented 3 years ago

Hi @KKKKKyle, this is a raw WebSockets client, socketio is a software that has multiple transport layers, WebSocket being one of them. I'm afraid this lib won't work with it without some modifications. It should work if you use a raw python WebSocket server tho (not socketio)