From: Alexander P. <pz...@pz...> - 2008-10-14 16:20:53
|
Hi, I'm trying to use the turnserver as a solution for NAT traversal for a very restricted network environment with only TCP traffic allowed by firewall. If TCP is being used as a transport between client and server, the following problem occurs. If client sends more that one TURN message to the server, only the first message is handled by server normally, all other messages cause server to print "Bad STUN / TURN message" diagnostics. Looking to a server code I came to conclusion that this is due to a way how TCP reception is implemented in the server. Server calls recv() for a TCP socket and assumes that the returned data is a TURN message. This assumption is not correct. TCP is a stream rather that message protocol, it doesn't preserve message boundaries. It means that recv() may return more that one message at once, or message may be split between consecutive recv()s and so on. The only correct way to deal with TCP is to reconstruct message boundaries based on a message size transmitted in a message headers. Data from TCP socket should go to some temporary buffer, and only when entire message is available it needs to be processed. -- Hope it helps, Wishes, Alexander Pevzner (pz...@pz...) |