   SDL_net losing sent packets
  Hello everyone,I'm currently using SDL_net for a little casual game which uses multiple clients, which is why I have to use socketsets.I now have the problem, that in cases where I send several packets quickly one after another from the client, the receiving server seems to be missing some packets.Here is my "receive code":void CGameServer::ListenTcpPackets()  { TRACELOGGER.Enter("CGameServer::ListenTcpPackets"); try {   cnt = SDLNet_CheckSockets(mSocketSetConnected, 5);   if ( cnt > 0 )   {  for ( ConnectedPlayersType::iterator it = mConnectedPlayers.begin(); it != mConnectedPlayers.end(); it++ )  { TCPsocket s = (*it).get()->tcpSocket; while ( SDLNet_SocketReady(s) )this->ReceiveTCP(s);  }   } } catch(...) {TRACELOGGER.LeaveBad("CGameServer::ListenTcpPackets");throw; } TRACELOGGER.LeaveGood("CGameServer::ListenTcpPackets");  } // ListenTcpPacketsThis is the ReceiveTCP() part:common::CNetworkPacket::ptrType CTcpReceiver::ReceiveTCP(const TCPsocket& socket, bool highPriority, bool autoPushBack)  {TRACELOGGER.Enter("CTcpReceiver::ReceiveTCP");    // ENTER CRITICAL SECTION    SDL_LockMutex(mTcpQueueMutex);    mIsReceiving = true;    common::CNetworkPacket::ptrType packet = networking::tcp::ReceivePacketTCP(socket, mTcpBuffer);    if ( common::CNetworkPacket::ptrType() != packet )    {   DEBUGLOGGER.Log("CTcpReceiver::ReceiveTCP: Received TCP packet");   if ( autoPushBack ) this->PushTCPQueue(S_QueueEntry(packet, socket), highPriority );    }    mIsReceiving = false;    SDL_UnlockMutex(mTcpQueueMutex);    // LEAVE CRITICAL SECTION TRACELOGGER.LeaveGood("CTcpReceiver::ReceiveTCP");    return packet;  } // ReceiveTCPAnd here is ReceivePacketTCP():networking::common::CNetworkPacket::ptrTypeReceivePacketTCP(const TCPsocket& socket, char* pBuffer){    TRACELOGGER.Enter("ReceivePacketTCP");    int recvLen = SDLNet_TCP_Recv(socket, pBuffer, TCP_PACKET_SIZE);    if ( recvLen > 0 )    {   networking::common::CNetworkPacket::ptrType packet = networking::common::CPacketDataFactory::Reconstruct((char*)pBuffer, recvLen);   TRACELOGGER.LeaveGood("ReceivePacketTCP");   return packet;    }    TRACELOGGER.LeaveBad("ReceivePacketTCP (nothing received)");    return networking::common::CNetworkPacket::ptrType();}To explain my problem again on this given code - following happens:The client tries to connect to the server. If the connection succeeds, the server responds with an "Connection accepted" packet.The client then sends a "RegisterPlayer" packet, and receives a packet with his assigned player id.Using that id the client can then join a game.The network packets within this joining a game process are sent back and forth pretty fast.Now in most cases the server does not receive the "join game" packet. It simply does not arrive, even though the client sent it.My question now is: What happens, when I sent packets faster, that I receive them?Does SDL_net somehow buffer the packets in some sort of fifo queue? Because that is what I would except.Thanks a lot for any help in advance!Greetings,Chris   
  The problem is related to how TCP works. TCP is a streaming protocol - it doesn't support "packets". What you send will come out the other end, byte by byte, but not necessarily in the exact units you sent it in.What is probably happening is that two or more packets are being merged, but your code discards the later messages. See the Forum FAQ, question 14.You need to be able to distinguish your messages, by using message identifiers or explicitly prefixing messages with the length (or a combination of the two).Your code needs to do something like this per client:// add network data to buffer (don't overwrite!)client.buffer += socket.read()while buffer.size() > header.size(){   header = interpret the start of the buffer as a header.   length = packet_length(header)   if buffer.size > header.size() + length   { remove the message from the front of the buffer. place the message in your queue.   }   else   {  return   }}The message header is at least a length value or a message id, or something more complicated.   ;  Ah, ok - then i "just" need to enhance my packet reconstruction factory a bit.This class already takes a binary stream and reconstructs a network packet from the first 4 bytes.It just needs to be able to create an array of packets from a single stream.Thanks a lot!   ;  Not really - it just needs to be able to return one message and buffer everything else. If you just change it to return multiple messages without addressing the buffering issue, you will still get problems when it receives only half a message.   