Client Socket Disconnection

Hi

I am writing a application which conatins a server application and mutliple clients. These all communicate using a Socket. (in TCPIP mode)

Whilst I can connect multiple clients and send messages individually to each I seem to be having issues with disconnection.

1. If I call Socket.Disconnect at the client end I get my server ends DataRecieved method being fired and can catch the "Forced Disconnection" exception. All fine and dandy, although any other clients connected also seem to become disconnected. This seems to be exactly what I want to be able to record a client has disconnected from the server, if only all the other clients did not disconnect at the same time.

----------------------------------------------------------------------------------------------

2. If the client uses the asynchronous Socket.BeginDisconnect I recieve an empty packet at the Server and can therefore determine that the socket is disconnecting.

If at this point:

2.1 The server calls Disconnect on the socket the OnDisconnected callback is never fired at the Client where I would call EndDisconnect. It is not until the server attempts another send that a DataRecieved "Forced Disconnection" exception is thrown at both ends. This is not reflective of the fact that the Client is disconnecting which is the event I need to record and is only caught on the next attempt to send to it rather than when the disconnection occurs.

2.2 If the server calls BeginDisconnect neither the Client or Servers OnDisconnect callback is fired but the DataRecieved at the Client is triggered and a Forced Disconnection" exception is thrown. This seems a bit backwards since in actual fact the reverse is true, the client is asking to disconnect from the server.

2.3 If nothing is done at the server it continually recieves null packets....until memory is exhausted.

Can someone tell me what I am doing wrong am

I don't understand why when using the asychronous BeginDisconnect I never see the OnDisconnected callback called (to avoid confusion this is the callback passed into the BeginDisconnect method).

Also how come in some situations the exception is thrown and others you simply recieve empty packets

Any help will be much appreciated.

Cheers
Tom Pearson



Answer this question

Client Socket Disconnection

  • zack

    This question is better suited for the Networking and Communication forum. Please reserve the C# forum for questions specifically related to C# itself. I'm moving your post to the Networking and Communication forum where someone will probably be better able to help you. Thanks.

    Michael Taylor - 6/15/06


  • Client Socket Disconnection