Jump to content

  • Log In with Google      Sign In   
  • Create Account


Correctly establishing a server/client connection


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Xanather   Members   -  Reputation: 703

Like
0Likes
Like

Posted 13 October 2012 - 08:21 AM

Ive started to develop a multiplayer game, its going well, only just started though. I have one problem that I cant exactly get my head around though.

When a client connects to the game server several messages are sent back and fouth between the client and server in order to establish a connection (like a sequence of verify bytes, version information, login details).

Say if though, the versions between the client/server are different and the error of "Different client/server version." displays on the game client. How would I cancel/close the sockets which I have created in a correct manner. Right now I am just closing the socket (.net's TcpClient) on both the server and the client. But the thing is once the TcpClient is closed on one end it also closes automatically on the other end (due to the transmission control protocol id issume, or winsock).

Question: How would I close these sockets correctly on both ends?

I hope you understand what I am saying,

All replies are appriciated.
Thanks,
Xanather.

Edited by Xanather, 13 October 2012 - 08:24 AM.


Sponsor:

#2 hplus0603   Moderators   -  Reputation: 4980

Like
0Likes
Like

Posted 13 October 2012 - 02:45 PM

Look up the shutdown() function.

Note that the socket itself doesn't get "closed" on the other end, just made an error to write to it. You still need to close()/closesocket() the socket handle to reclaim the kernel file descriptor/handle.
enum Bool { True, False, FileNotFound };

#3 Xanather   Members   -  Reputation: 703

Like
0Likes
Like

Posted 14 October 2012 - 05:12 AM

Look up the shutdown() function.

Ok, will do.

What do you mean by it doesnt get closed if the socket had a error to writing/reading? With .net's TcpClient the .Connected property always returns true until a read/write failes (even once) so thats strange.

Xanather.

#4 hplus0603   Moderators   -  Reputation: 4980

Like
1Likes
Like

Posted 14 October 2012 - 10:12 PM

"Connected" and "Closed" are different concepts.

enum Bool { True, False, FileNotFound };

#5 Xanather   Members   -  Reputation: 703

Like
0Likes
Like

Posted 15 October 2012 - 06:25 AM

Ok, the way Ive set it up now is probably correct then, thanks Posted Image Just got confused, read up on the Close() method and it does indeed release all managed/unmanaged resources.

The Close method marks the instance as disposed and requests that the associated Socket close the TCP connection


Edited by Xanather, 15 October 2012 - 06:27 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS