I'm working on a server f开发者_开发技巧or the game Minecraft, which shows a dark-red screen when the player is disconnected. I'm disconnecting players like this:
Socket.Shutdown( SocketShutdown.Both );
Socket.Close();
I seem to be unable to write data after that, but the disconnected screen doesn't appear. It only appears when I completely terminate the server application, which indicates that the connection isn't closed at all.
What am I doing wrong?
Edit:
socket.BeginAccept( new AsyncCallback( AcceptClient ), null );
private void AcceptClient( IAsyncResult result )
{
try
{
// Initialize player
Socket client = _socket.EndAccept( result );
.
Log( "Received unrecognized packet from " + player.IPAddress() + ", disconnecting client!" );
player.Disconnect();
_clients.Remove( player );
I don't know what the API looks like for Minecraft, but odds are that there's a command you need to send to the client first, to let them know they've been disconnected.
What about Socket.Disconnect()
?
精彩评论