tcpclient stream read
-
i'm working on a server/client app and i'm running into problems. i would like the client to update when the server sends data to it. the problem is with Stream.Read() . This method will hang the application until either data is received, or an exception is generated. is there a way to check if data exists before you call the read method? this is a snippet of the code i'm using:
TcpClient tcpclnt = new TcpClient(); tcpclnt.Connect("10.10.10.10',8001); Stream stm = tcpclnt.GetStream(); .... listen() { try { byte[] bb = new byte[100]; int k = stm.Read(bb,0,100); for ( int i=0 ; i
-
i'm working on a server/client app and i'm running into problems. i would like the client to update when the server sends data to it. the problem is with Stream.Read() . This method will hang the application until either data is received, or an exception is generated. is there a way to check if data exists before you call the read method? this is a snippet of the code i'm using:
TcpClient tcpclnt = new TcpClient(); tcpclnt.Connect("10.10.10.10',8001); Stream stm = tcpclnt.GetStream(); .... listen() { try { byte[] bb = new byte[100]; int k = stm.Read(bb,0,100); for ( int i=0 ; i
-
i'm working on a server/client app and i'm running into problems. i would like the client to update when the server sends data to it. the problem is with Stream.Read() . This method will hang the application until either data is received, or an exception is generated. is there a way to check if data exists before you call the read method? this is a snippet of the code i'm using:
TcpClient tcpclnt = new TcpClient(); tcpclnt.Connect("10.10.10.10',8001); Stream stm = tcpclnt.GetStream(); .... listen() { try { byte[] bb = new byte[100]; int k = stm.Read(bb,0,100); for ( int i=0 ; i
-
i'm working on a server/client app and i'm running into problems. i would like the client to update when the server sends data to it. the problem is with Stream.Read() . This method will hang the application until either data is received, or an exception is generated. is there a way to check if data exists before you call the read method? this is a snippet of the code i'm using:
TcpClient tcpclnt = new TcpClient(); tcpclnt.Connect("10.10.10.10',8001); Stream stm = tcpclnt.GetStream(); .... listen() { try { byte[] bb = new byte[100]; int k = stm.Read(bb,0,100); for ( int i=0 ; i
Run the "listener" in its own thread. This will overcome the freeze while waiting for the server to accept your connection. You may like to have a look at the NetworkStream.DataAvailable property, this property returns true if data is available on the stream to be read; otherwise, false.
-
threads ;) leppie::AllocCPArticle("Zee blog");
Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.leppie wrote: threads You said this twice, are you silently suggesting *multi-threading*? :laugh: -Nick Parker