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?

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

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.