So for my game I have a server thread (S) and packet sender thread (PS). First I was gonna ask about the problem I had with client not geting servers packets, but during writing I figured out what I missed and corrected it.
Now I ask for opinions, is this good way to program networking or there are better ways? Like most stuff beyond connecting and receiving data on one side, I did this myself couse there are no tutorials or books on how to do server - client thing right way (beyond trivial connecting to server, sending data and server responding to received data), at least I couldn't find them. Tell me what do you think of this logic:
S waits for connection in non-blocking mode. Client connects and S accepts. On clients side channel is register for OP_READ, set to non-blocking mode and added to clients list after establishing the connection to server, and on server side all that is done when accepting connection. Both sides have now S that listens for that channel's data, and a PS that sends data through the channel on the other side every X seconds. If error occurs or connection is closed then channel is removed from clients list and closed (thus deregistering OPs as I understood). If more clients connect to server they will be added to the clients list and PS on server side goes through the list, sending everybody data. So S and PS on both ends are the same except they have IF statements do process server's or client's packets differently.
Oh yeah I find the biggest problem is actually synchronizing the data so threads won't access it at the same time... and I've got a lot of data shared between 3 threads (animation, S, PS). It's really annoying and I was thinking of restructuring things so they share less data. For example, for client to send players stats and position, PS needs to access animation thread and take the data... same thing about processing received data where S needs to set animation's variables and so on... don't get me started how many data S i PS share... If there is a good book or tutorial who would describe the best logic for this I would be gratefull. Thanks to all for reading this huge post