Tuesday, 15 May 2012

network programming - c# Make TcpServer Block -



network programming - c# Make TcpServer Block -

i using c# create server , client. want blocking purpose of doing. when utilize networkstream.read(), blocks , similar that. problem when utilize networkstream.readbyte(), doesn't block. instead returns -1 when there no incoming byte. how can create networkstream.readbyte() block networkstream.read()?

i've tried enclose networkstream.readbyte() in networkstream.dataavailable didn't work either. wantnetworkstream.readbyte() block. ideas?

why not use:

byte[] buf = new byte[1]; stream.read(buf, 0, 1);

edit: of course of study if you're doing lot don't allocate new buffer each time, store field on object & allocate in constructor.

c# network-programming tcpclient tcplistener

No comments:

Post a Comment