我的数据来自串行端口,我想在通过TCP/IP将其发送到客户端之前将其存储在FIFO缓冲区中。我该怎么做呢?
为什么需要FIFO?你可以从SerialPort
和TcpClient
得到Stream
。复制一个到另一个:
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);
}