Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

gandolf1212

Please help me

This topic is 5423 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, I''ve been at this for 3 days now, used every tutorial here, didn''t even go to sleep last night, ready to cry... I''m trying to do client / server interaction. My client is a flash based tic tac toe game, my server is a Win32 command line app running winsock. I''m using non-blocking sockets. The server should support 10 players at once, directing messages from one player to another. The server should never shutdown. The error I''m having is, when the client closes, the server dies. It doesn''t even die like it should, it just spams the screen with, what I think, is just crap from the buffer, making the error extreamly hard to debug. The server isn''t even sending any data to it when it''s crashing, just looking to get data. I think the error may be in here:
void cServer :: checkMessages(){

  fd_set input_set, exc_set;
  int s, nfds; 
  char buffer[1024];

  FD_ZERO(&input_set);
  FD_ZERO(&exc_set);
  nfds = 0;

  for(int t=0; t<10; t++){
   if(Clients[t].state){
    FD_SET(Clients[t].mySocket,&input_set);
    FD_SET(Clients[t].mySocket,&exc_set);
    nfds++;
   }
  }

  s = select(nfds,&input_set,NULL,&exc_set,&timeout);

  if(s > 0){
   for(int t=0; t<10; t++){
    if(Clients[t].state){
     if (FD_ISSET(Clients[t].mySocket,&exc_set)){
      char *ClientIp = inet_ntoa(Clients[t].mySocketAddr.sin_addr);
      cout<
But I don''t know. If anyone knows how I''m supposed to be debugging this or spots an error let me know. Don''t send me to another tutorial though, I''ll quit the project before I look at another one.
I think I''m gonna try to get some sleep now, head is killing me but with all the coffee I don''t even feel like lying down.
Thanks for any help, this project is really getting the better of me.
Regards,
Trent

Share this post


Link to post
Share on other sites
Advertisement
Log all messages you receive to a file, each time you receive them. Then, find out what messages are received after the client has shut down.

Share this post


Link to post
Share on other sites
why do you have this line twice : if(Clients[t].state)

I have not used select before but I think i see where you server spits out the buffer:
if(Clients[t].state){ if ((FD_ISSET(Clients[t].mySocket, &input_set))){ recv(Clients[t].mySocket,buffer,1024,0); printf("%s\n", buffer); }

Don''t ever printf a buffer you got from a socket. it could contain weird characters causing your program to do weird things. For example, your program could start beeping uncontrollably. Who knows, it may be possible that some characters cause your program to crash.

Another thing, when you do recv() you do not neccesarally get a null terminated string so you can core dump your program by printing the stuff you got from recv()

Basically: string functions and sockets don''t mix

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!