943,023 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 532
  • C++ RSS
Jan 7th, 2010
0

Help converting recive function winsock to sdl_net.

Expand Post »
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):

C++ Syntax (Toggle Plain Text)
  1. int AzSoket::resv(string &buf,int timeout)
  2. {
  3. buf = "";
  4. char buffer[0];
  5. bool cont = true;
  6. while(SDLNet_TCP_Recv(qsd, buffer, 1) > 0 && cont)
  7. {
  8. if(buffer == "}")
  9. {
  10. cont = false;
  11. return 1;
  12. }
  13. buf += buffer[0];
  14. }
  15. }


Yet this still does not work... any help please?
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
azjherben is offline Offline
33 posts
since May 2009
Jan 7th, 2010
1
Re: Help converting recive function winsock to sdl_net.
Yet another buffer overflow, I suppose. How much space did you allocate for char buffer ?
Reputation Points: 707
Solved Threads: 185
Practically a Posting Shark
nezachem is offline Offline
843 posts
since Dec 2009
Jan 7th, 2010
0
Re: Help converting recive function winsock to sdl_net.
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:

C++ Syntax (Toggle Plain Text)
  1. int AzSoket::resv(string &buf,int timeout)
  2. {
  3. buf = "";
  4. char buffer[100];
  5. bool contv = true;
  6.  
  7. while(SDLNet_TCP_Recv(qsd, buffer, 1) > 0 && contv == true)
  8. {
  9. string cbu = buffer;
  10. if(cbu.substr(0,1) == "}")
  11. {
  12. contv = false;
  13. return 1;
  14. }
  15. buf += buffer[0];
  16. }
  17.  
  18. }

The game gets a bit further, but it still freezes up and must be closed.
Last edited by azjherben; Jan 7th, 2010 at 7:26 pm.
Reputation Points: 10
Solved Threads: 1
Light Poster
azjherben is offline Offline
33 posts
since May 2009
Jan 7th, 2010
0
Re: Help converting recive function winsock to sdl_net.
I don't see anything funny here. Time to get a debugger, I'd say.
Reputation Points: 707
Solved Threads: 185
Practically a Posting Shark
nezachem is offline Offline
843 posts
since Dec 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: C++ Struct & Qt Client Server
Next Thread in C++ Forum Timeline: how can i get dual interface of mouse and keyboard?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC