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?
Asked
Active
Viewed 715 times
-4
-
1Good. For this you need Queue
. – Tigran Jun 25 '14 at 21:13 -
Isn't this what streams are for? – spender Jun 25 '14 at 21:22
1 Answers
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