C# and Web Sockets

Going back to the C# websocket implementation issue, I was looking at https://github.com/sta/websocket-sharp but I feel like I should look at other implementations. After reviewing other solutions such as Flex (https://github.com/statianzo/Fleck) and also Microsoft’s native websocket implementation, Fleck seemed to require a Fleck websocket server which I was not willing to implement as I already had a working server implementation using the node websocket package. For C# websocket support, I have decided to use websocket sharp, which can be found here https://www.nuget.org/packages/WebSocketSharp.

Had an issue with Unity not compiling with the websocketsharp nuget package installed, til I realised the DLL for it actually needs to be in the Unity asset folder.

Next I ended up having issues with getting my web socket server to actually receive messages, OR having issues with my unity project actually SENDING messages. Either one of those could be true, however the web socket server receives the connection request so I thought it was actually the unity project not correctly sending the message.

So I fixed it. I needed to manually wait until the connection to the server has been established, except there is no callback available to tell when this has happened but there is a thing that exists called WebSocket.IsAlive which returns true after the connection to the server has been established. I can use this with a coroutine to determine when the connection has been established.

Yay. Quick messages, working fast.