-3

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?

2
  • 1
    Good. For this you need Queue<T>. Commented Jun 25, 2014 at 21:13
  • Isn't this what streams are for? Commented Jun 25, 2014 at 21:22

1 Answer 1

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);
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.