I would use TcpClient. It sits on top of Socket and is an abstraction on Socket. TcpClient has a GetStream that returns a Stream object. Then, to read a stream, you can simply use a stream reader.
For example:
tcpClient = new TcpClient(host, port)
{
ReceiveTimeout = readTimeout
};
stream = tcpClient.GetStream();
streamReader = new StreamReader(stream, Encoding.ASCII);
streamWriter = new StreamWriter(stream, Encoding.ASCII)
{
AutoFlush = true
};
return this;
What allows (snippet):
s treamReader.Read(myReadBuffer, 0, myReadBuffer.Length)
source
share