c# - Port checking tool causes infinite packet received loop on TcpClient server -


i've written relatively basic asynchronous server boots task accept clients , each client boots task accept incoming packets, code follows:

        messagelisteningtask = new task(async () => {             while (true) {                 byte[] buffer = new byte[256];                 try {                     await tcpclient.getstream().readasync(buffer, 0, buffer.length);                 } catch {                     break;                 }                 string data = encoding.utf8.getstring(buffer).trim('\0', '\n', '\r', '\t', ' ');                 onmessagereceived(data);             }         }); 

this seems work pretty things, , after routing through class splits tokens based on token @ start, quite effective listener.

except, given naivety topic, seem have done stupidly somewhere in implementation, , checking tool: http://www.yougetsignal.com/tools/open-ports/ seems break loop , cause trigger onmessagereceived no data.

i'm not entirely sure procedures take diagnose issue, , figure it's how information stream operates, hoping experience in topic me solve issue explain causing it. if it's relevant, it's running under mono on ubuntu, runs can't see being issue.

i happy provide additional information, or check anything.

thanks!

from documentation of readasync:

https://msdn.microsoft.com/en-us/library/hh137813(v=vs.110).aspx

"return value type: system.threading.tasks.task task represents asynchronous read operation. value of tresult parameter contains total number of bytes read buffer. result value can less number of bytes requested if number of bytes available less requested number, or can 0 (zero) if end of stream has been reached."

in loop readasync must returning 0 because reached end of stream.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -