c# - .Net Socket Read function blocking issue -


i have client-server application in c#.net , using tcp socket. have used following function aggressive close of socket object.

void closesocket(socket socket) {       if(socket != null)       {            socket.shutdown(ocketshutdown.both);            socket.close();       }  } 

in normal condition function works , method returns 0 bytes returned read function.

but whenever client process terminated taskmanager server program blocks read function of network stream.

how can workaround read blocking function ? don't want use asyncread function because whole project uses blocking strategy write can't change async pattern.

thanks, in advance.

i'm assuming saying when connection isn't closed cleanly client, server can end blocking @ read indefinitely, if client has terminated abruptly. if so: yes, happens. if want use synchronous read methods, should use timeouts, in particular receivetimeout. if have multi-message protocol, may worthwhile adding kind of heartbeat message periodically, allow correctly identify true zombies idle connections (for example: if sending heartbeat every minute, , haven't seen activity on connection 3 minutes, hit shovel).


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -