954,176 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help converting recive function winsock to sdl_net.

I had a program that ran fine with Winsock.
But that only works on Windows.
So I decided to switch to SDL_net.
I thought I did okay, no syntax errors or anything when I compiled.
But on run the program froze up.

So I read about various SDL functions.
When I read about the receive function I noticed it said it will try to receive the exact amount of bytes you specify.

So I tryed to have my server (which is still winsock written) to end all of it's packets (used parts) with a }.

And this was the code I put in my client (SDL_net):

int AzSoket::resv(string &buf,int timeout)
{
buf = "";
char buffer[0];
bool cont = true;
while(SDLNet_TCP_Recv(qsd, buffer, 1) > 0 && cont)
{
if(buffer == "}")
{
cont = false;
return 1;
}
buf += buffer[0];
}
}

Yet this still does not work... any help please?

azjherben
Light Poster
33 posts since May 2009
Reputation Points: 10
Solved Threads: 1
 

Yet another buffer overflow, I suppose. How much space did you allocate for char buffer ?

nezachem
Posting Shark
903 posts since Dec 2009
Reputation Points: 719
Solved Threads: 194
 

I changed 'char buffer[0];' to 'char buffer[100];' and still get the same problem.
I also added a line of code...
This is the function now:

int AzSoket::resv(string &buf,int timeout)
{
buf = "";
char buffer[100];
bool contv = true;

while(SDLNet_TCP_Recv(qsd, buffer, 1) > 0 && contv == true)
{
string cbu = buffer;
if(cbu.substr(0,1) == "}")
{
contv = false;
return 1;
}
buf += buffer[0];
}

}


The game gets a bit further, but it still freezes up and must be closed.

azjherben
Light Poster
33 posts since May 2009
Reputation Points: 10
Solved Threads: 1
 

I don't see anything funny here. Time to get a debugger, I'd say.

nezachem
Posting Shark
903 posts since Dec 2009
Reputation Points: 719
Solved Threads: 194
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You