a few questions before I design my protocol.

Please post support and help requests here.
Posts: 2
Joined: 05 Aug 2013, 20:07

a few questions before I design my protocol.

Postby sorressean » 06 Aug 2013, 17:35

hello all:
I am working on a multi-player game using Poco. I had a couple of questions.
First, is the TcpSocketConnectionFactory that uses the thread pool set up so that it will distribute the connections across the pool?
Second, how do people usually structure their run function? Do you just have it read x bytes to get your packet headers, then read the packet header? can I set the socket to blocking without any problems so that it will block until there is data to read?

Posts: 1268
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: a few questions before I design my protocol.

Postby guenter » 07 Aug 2013, 09:55

TCPServer uses a thread-per-connection model, so it may not be the best choice for a multi-player game server with hundreds or thousands of simultaneous users. For that, SocketReactor or a custom select loop may be more useful.
Regarding the run() function, a good way is to read the fixed-size packet header first, then read the remaining bytes. This approach can be used with both blocking and non-blocking sockets. Of course, for non-blocking sockets, you'll have to handle the case that you'll may need multiple recv() calls to receive the complete header or body.

Posts: 19
Joined: 23 Feb 2012, 18:13

Re: a few questions before I design my protocol.

Postby Royce » 21 Aug 2013, 20:54

I recently had a problem where it turned out I needed to handle multiple recv()'s for a packet header a lousy four bytes in length. It was a blocking TCP socket. Looking at the wireshark I noticed that I got clumps of packets whose length added up to 8192 bytes. Somebody along the way was rearranging the packet structure for a 8192 frame size and then my recv network rearranged it again to fit a 1460 MTU. The result was that every once in a while a four byte header would split across clumps and the delay between clumps was enough for recv to return with what it had up to that point.

So, I'd suggest you code for the possibility of multiple recv()'s for anything larger than one byte regardless of what type of socket you use.

Return to “Support”

Who is online

Users browsing this forum: No registered users and 4 guests