Correctly establishing a server/client connection

Started by
3 comments, last by Xanather 11 years, 6 months ago
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.
Advertisement
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 };
Look up the shutdown() function.[/quote]
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.
"Connected" and "Closed" are different concepts.
enum Bool { True, False, FileNotFound };
Ok, the way Ive set it up now is probably correct then, thanks smile.png 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[/quote]

This topic is closed to new replies.

Advertisement