Problems with SDLNet_TCP_Recv going NULL

Hello all,

Networking newb here. I’m also new to the list.

I’m having trouble using SDLNet_TCP_Recv( ). In
particular, this line of code:

int result = SDLNet_TCP_Recv(socket, container,
AMOUNTTOSEND);

//AMOUNTTOSEND is 80 for this example.
// socket is a TCPSocket
// container is a void pointer

After that line above, socket becomes NULL, as well as
the associated ipaddress and port.

I have tried setting AMOUNTTOSEND to something
smaller, like 5 or 10, and it receives fine. (socket
retains its address. With that, I’m wondering if 80 is
an incorrect value to send.

//CODE SNIPPET
bool CSOCKET::recieve(void *container)
{
int len = AMOUNTTOSEND;
int result = SDLNet_TCP_Recv(socket, container,
1);

if(result < len)
return false;

return true;

}
//END CODE SNIPPET

The call to the member function is:
//CODE SNIPPET
for(int i = 0; i < clients.size(); i++)
{

  ntwMsg.cID = (int)ENEMY; //ENEMY = enum
  ntwMsg.pMessage = &EnemyStruct; 
  int length = sizeof(EnemyStruct); 
  clients[i].send(&ntwMsg);
}

//END CODE SNIPPET

clients is a vector of CSOCKETS
ntwMsg is a struct with int cID, void * pMessage

Am I sending/receiving correctly? Any help would be
appreciated! Thanks!

Ohm Unmongkolthavong__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

int result = SDLNet_TCP_Recv(socket, container,
AMOUNTTOSEND);

//AMOUNTTOSEND is 80 for this example.
// socket is a TCPSocket
// container is a void pointer

After that line above, socket becomes NULL, as well as
the associated ipaddress and port.

SDL_net can’t change (socket) in that call, which suggests that
(container) isn’t pointing to (AMOUNTTOSEND) bytes of memory that you
can safely write to…so you write however much data can fit into
(container), then overflow that buffer and write over the memory that
stores (socket), etc.

–ryan.