C# Keep Asynchronous Socket open -


i have asynchronous server , several asynchronous clients connecting it. client should start connection , keep connection open until terminates can send , receive data on demand.

i using asynchronous client , server code in:

https://msdn.microsoft.com/en-us/library/fx6588te%28v=vs.110%29.aspx

https://msdn.microsoft.com/en-us/library/bew39x2a%28v=vs.110%29.aspx

i've made ipendpoint , socket class objects can called everywhere in class:

static ipendpoint remoteep = new ipendpoint(ipaddress.parse("xxx.xxx.xxx.xxx"),12345);  static socket client = new socket(addressfamily.internetwork,sockettype.stream,protocoltype.tcp); 

i've commented out socket closure in startclient() function , did same on server:

// client // release socket. client.shutdown(socketshutdown.both); client.close();  // server handler.shutdown(socketshutdown.both); handler.close(); 

then called client's

send(socket client, string data) this:  send(client,"this test 1<eof>"); senddone.waitone();  receive(client); receivedone.waitone();  console.writeline("response received : {0}",response); 

but kinds of exceptions, "socket null".

how can start connection server, keep connection open indefinitely , use part of code?


Comments