TCP events in C#?

  • Thread starter Thread starter Peter Steele
  • Start date Start date
P

Peter Steele

I'm writing a client/server application that uses TCP/IP to communicate. I
using the TcpClient/TcpListener classes to set up the communication and
these work well, but I'd like to set up some events to trap when data
arrives from the server to the client and vice versa. I've used some TCP/IP
components in C++ Builder where this kind of thing is really easy. Is there
something equivalent in C#?
 
When You use simplified networking API (TCPClient, TCPListener). You must
obtain special version of Stream class called NetworkStream which supports
Read and Write operation. After calling Read method on NetworkStream,
execution ofcode is blocked until data is available from counterpart. int
bytesRead = 0;
NetworkStream ns = myTcpClient.GetStream(); byte[] readBuffer = new
byte[4096]; do
{bytesRead = ns.Read(readBuffer, 0, readBuffer, readBuffer.Length ); }while
(bytesRead > 0); Events driven model is not supported in .Net networking.


HTH
RENE STEIN, C# MVP <[email protected]> Sun, 11 Jul 2004 18:27:12 +0200

=== Posted with Qusnetsoft NewsReader 2.2.0.1

----- Original Message -----
From: "Peter Steele" <[email protected]> Sent: Sun, 11 Jul 2004 04:09:15
Subject: TCP events in C#?


I'm writing a client/server application that uses TCP/IP to communicate. I
using the TcpClient/TcpListener classes to set up the communication and
these work well, but I'd like to set up some events to trap when data
arrives from the server to the client and vice versa. I've used some TCP/IP
components in C++ Builder where this kind of thing is really easy. Is there
something equivalent in C#?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top