.net - TCP sockets sr.readline prevents entering data on console? -
below find code. thing is, supposed "client chat" program able send message constantly. however, somehow app blocked console.readline() user prompted enter message once. workaround this? may using predefined read buffer?
static void main(string[] args) { tcpclient client = new tcpclient("127.0.0.1", 7777); try { stream s = client.getstream(); streamreader sr = new streamreader(s); streamwriter sw = new streamwriter(s); sw.autoflush = true; //console.writeline(sr.readline()); while (true) { console.write("message: "); string msg = console.readline(); sw.writeline(msg); if (msg == "chao") break; console.writeline(sr.readline()); } s.close(); } { client.close(); } }
i know isn't direct answer question, if have read of stephen cleary's tcp/ip .net sockets faq lots of information using .net sockets.
http://blog.stephencleary.com/2009/04/tcpip-net-sockets-faq.html
Comments
Post a Comment