TCP connection optimalization in C#

  • Thread starter Thread starter Seeter
  • Start date Start date
S

Seeter

Guest
Hi,

I make app in Visual C# that connets to the measuring device over ethernet TCP. In the manual from the device, there is an example of code, that establishes connectio:

TcpClient tcpClient = new TcpClient();
tcpClient.Connect("192.168.66.2", 1024);
NetworkStream stream = tcpClient.GetStream();
stream.Write(new byte[] { 0xF0 }, 0, 1);
while (tcpClient.Available < 2) { };
byte[] recievedData = new byte[2];
tcpClient.Close()

In case I set wrong number in while cycle, it gets stuck. How can I establish connection and communication withou waiting for data with while cycle? Stream write is code for device that represents request for data, than I expect some amount of data.

Continue reading...
 
Back
Top