My data is coming from a serial port and I'd like to store it in a FIFO buffer before sending it to the client via TCP/IP. How can I do it?
1 Answer
Why do you need a FIFO? You can get a Stream from both a SerialPort and a TcpClient. Just copy one to the other:
IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse("128.128.128.128"), 8888);
using(TcpClient client = new TcpClient())
using(SerialPort sp = new SerialPort("COM1"))
{
client.Connect(endpoint);
sp.Open();
Stream clientStream = client.GetStream();
Stream serialStream = sp.BaseStream;
sp.BaseStream.CopyTo(clientStream);
}