I've written a VB.Net app which connects to a remote IP/port combination that's outputting a steady stream of messages. The IP address could be localhost or it could be a remote machine.
The remote process can stop and start at any time and my process needs to connect to it and simply start receiving. There is no negotiation between the two about which ports to use.
My current code uses TcpClient and NetworkStream to read a byte at a time. This is converted to the corresponding ASCII character (all messages are ASCII text) and are appended to a string until an EOL character is received. Once it is then the line is added to a queue to be processed, the string is truncated and the process begins again. Whilst this works, listening a byte at a time is probably not the most efficient way to do this.
I now testing the app and I'm running into some serious performance issues. Although my current code works it can't handle the amount of data that is thrown at it. Whilst it can handle 500 messages a second, it really struggles at 1500 per second and peaks at 20% CPU.
I'm sure that the bottleneck is the reading of the data a byte at a time - is there a way to speed this up ? Ideally I'd love to read in a line of data at a time up until the EOL character is received but this capability doesn't seem to exist in the TcpClient.
Socket programming is not my strong point so maybe I'm missing something obvious. Help !