I have a custom game server I wrote in Node.js and want to write a C# Unity client for it. I am using websockets to transfer the data and have already made a pure web client for it in Javascript. I found the third party library websockets-sharp which I made a prototype client with, but it seems to have problems with threading which creates minor (but frustrating) lag, so I am wondering if I could use UNET to write the client instead.
I'm using websocket-sharp extensively in Nakama Unity Client and haven't encountered any lags. Could this potentially be an issue from the server? P.s. This is the code that interacts with websocket-sharp: https://github.com/heroiclabs/nakama-unity/blob/master/Nakama/NClient.cs#L289
Could you please tell us a bit more about the game? It's really different if that a fps or turn based game.
Also when you say its using WebSockets is that for HTTP(s) Requests or are you referring to using TCP or UDP Socket connections? The lag that your referring to could be where its not multi threaded and when its receives data that needs to be processed it goes off to do that which might take a little while to complete and where its single threaded everything else has to wait until its completed what it doing, that would cause delays. Like or113 has already stated, it all depends of the type of game, like a turn based game could work using HTTP(s) requests and responses where as FPS would have issues and would require UDP or TCP socket communication. I myself am using the LLAPI (NetworkTransport) which used UDP which seems to be going well so far. Paul
I ended up writing my own TCP Server Library designed specifically for my game which uses Threads, Queues etc and I am about 72% complete for the server side. Paul
Sorry for the delay in the reply, erm well I am still adding stuff to it, its more custom written for my games that I am currently working on and my future ones. My Networking Library is written externally from Unity so that I can create a dedicated server that can be written away from Unity and at the same time have the Client side of things written in Unity. Due to current health issues I had to stop work on my library, but I am starting to come back to work on it. There is nothing special about my library, I am just using TcpListener / Sockets for the Server and TcpClient / Socket for the client. I am also thinking of adding support for UDP and WebRequest to the library, but this will probably be later on. Also both sides of the networking (Client and Server) i.e. the network loop are Threaded by one or more threads (Primary and Support Threads) which is configurable depending on the type of game, this might also be an automated feature later on. I also use multiple threads for the message queues like for reading and writing of network messages etc. I have also created my own ThreadManager based around System.Threading.Thread which allows me to easily create, start, stop and remove threads on the fly. The hard part was when I added the Threading stuff where it broke my current code lol. Paul