-4

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?

Omar
  • 16,329
  • 10
  • 48
  • 66

1 Answers1

0

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);
}
spender
  • 117,338
  • 33
  • 229
  • 351