Advice please?

Started by
1 comment, last by DvDmanDT 18 years, 8 months ago
Hello everyone.. I'm making an RTS, with a client-server model.. It will work by sending game-messages.. Pretty simple and straight forward.. Each client will send their messages to the server, which will then send it back and to all other players as well (so that the game runs synchronized).. So.. I should use non-blocking sockets for this, right? Or blocking with threads? Oh, and is there any way to know how much data can be read from a socket? I will be sending fixed size messages, of say 256 bytes each, and I would like to know if an entire message is recieved and ready to be read, or if I should wait another frame or two for it to get recieved.. More coming at a later point.. All help is appreciated..
Advertisement
Personally I do not prefer multithreading so I recommend using nonblocking sockets, unless you use selecct () and then it doesn't matter if they are blocking or nonblocking...
to see how much data has been recieved until now in your socket you should call recv (sock, buffer, length, MSG_PEEK); this will only check what there is now in the socket and copy it to the buffer and return the number of bytes currently availble, but it will also not delete the data from the queue so if u do recv again you will get the same data again. you can just wait until recv returns 256...
Ok, that was my initial thought.. Altough, it seems like a rather ugly way to do it.. .. Guess I'll go with that for now though.. Thanks.

This topic is closed to new replies.

Advertisement