Jump to content


Photo

receivemessage = 0


  • Please log in to reply
3 replies to this topic

#1 Ronchon le Nain

Ronchon le Nain

    GMC Member

  • GMC Member
  • 87 posts
  • Version:GM8

Posted 12 February 2012 - 08:35 PM

Hi,
In the server exemple of a game ( using 39 dll ), there is this code , for the part where client listens from incoming messages.
It says if receivemessage is below 0 means there's none, if it's >0 means there is one, but if its =0 it disconnects. Why ? 0 is the value returned automatically when connection is lost ?
Thanks!

while(1)
{
  
  size = receivemessage(sock, 0, buf_in)           //Recieve any messages on the player's socket
  //If no message than exit the while() loop
  if(size < 0) break;
  //If socket was closed gracefully                       
  if(size == 0)                             
  {
    instance_destroy(); //Then remove the player
    break;              //And exit loop
  }
}

  • 0

#2 Medusar

Medusar

    GMC Member

  • GMC Member
  • 1228 posts
  • Version:GM:Studio

Posted 13 February 2012 - 05:14 PM

Yes, essentially the receivemessage() function works like the WinSock recv() function, which returns 0 if the connection has been gracefully closed. (if it hasn't been gracefully closed, 39DLL returns -1 without telling you what the error was)
  • 0

#3 Ronchon le Nain

Ronchon le Nain

    GMC Member

  • GMC Member
  • 87 posts
  • Version:GM8

Posted 14 February 2012 - 11:29 AM

Thank you for your answer.
But what is the difference/reason/meaning of a gracefully closed connection and one that was not ?
In my client, i get "periods" where receivemessage() returns nothing but 0 for some steps, then it comes back to normal. Does it mean its a temporary connection loss with the server ?
  • 0

#4 Medusar

Medusar

    GMC Member

  • GMC Member
  • 1228 posts
  • Version:GM:Studio

Posted 14 February 2012 - 05:11 PM

"Graceful" means that you disconnected, but no error occoured. So if the other player shuts down the game, his computer tells your computer that the connecion has been closed. A non-graceful disconnect can happen for various reasons, for instance the other computer may crash or someone decides that it's fun to cut the network cable in two. But there may also be errors on your part, receivemessage() will also return 0 if you try to read from a closed socket, for example.

I don't know why you get the problem that it returns 0 for a while. I think it's really weird that the connection comes back on the same socket after a while.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users