- Home /
Best way to handle Sockets?
I've been writing my own Server for games for quite some time; Actually I guess you could say it's more of an API for game-server development. I've used it in a few games so far, however most have been Java games. I'm nowhere near as experienced with C# as I am with Java, which is the language my server has been written in.
Considering I'm using a stand-alone server, it seems like the best route would be to use the TcpClient class in the System.Net.Sockets
namespace. The problems I'm running into however are trying to figure out the best way to handle this.
Some people are recommending a CoRoutine to handle networking; However I have always handled my networking and rendering on seperate threads. (Java games). With Unity, it loves to complain about multithreading; However it is possible. (In fact, I do it.)
Currently what I'm doing is storing all of the logic that I need processed into a Queue
from the networking thread, then executing the logic in proper order during the Update call from MonoBehaviour.
I've been told this is a bad practice (However, I've not had any problems with it.) and I'm looking for answers.
"storing [...] need processed into a Queue [...]. [...] told this is a bad practice"
Do you have some sort of $$anonymous$$utex preventing the network thread from modifiing the queue during update? Which is itself raceless? What does it do with events while the queue is locked? That's the only thing I can think of that could be a problem.
Your answer
Follow this Question
Related Questions
Port not opening? 3 Answers
Simple dedicated server on the VDS 1 Answer
Unity networking tutorial? 6 Answers
can I implement networking using HLAPI where Host is not a player? 1 Answer