c# - Close Client Socket on disconnect -


i have server application listens clients. let's client lost internet connection , lost connection server.

does server automatically check when client disconnected? if not how may implement such thing?

main.cs http://pastebin.com/fhyperz7

serversocket.cs: http://pastebin.com/erw4tzdp

client.cs:

using system; using system.collections.generic; using system.linq; using system.text; using system.net.sockets;  namespace jm2 {     class client     {         private int clientconnectionid;         private socket clientsocket;         private string clientip;         private byte[] clientbuffer = new byte[1024];          public client(int connectionid, socket connectionsocket)         {             clientconnectionid = connectionid;             clientsocket = connectionsocket;             clientip = connectionsocket.remoteendpoint.tostring();             clientsocket.beginreceive(clientbuffer, 0, clientbuffer.length, socketflags.none, new asynccallback(dataarrival), null);         }         public void disconnect()         {             clientsocket.close();         }         private void dataarrival(iasyncresult iar)         {             int bytesreceived = clientsocket.endreceive(iar);             clientsocket.beginreceive(clientbuffer, 0, clientbuffer.length, socketflags.none, new asynccallback(dataarrival), null);         }     } } 

see answer question:

tcpclient.close doesn't close connection

basically no 1 knows if connection closed until try send data. if fails, connection closed.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -