0

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?

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by nezachem
1

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

0

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.

Edited by azjherben: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.