如何在同一端口 C# 中创建同时处理 UDP 和 TCP 的客户端?

How to create Client working on both UDP and TCP in the same port C#?

当我在客户端使用下一个代码时:

IPEndPoint EndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8001);
UdpClient UDPServer = new UdpClient(EndPoint);
TcpClient TCPClient = new TcpClient(EndPoint);

我遇到一个例外,它只允许使用单个套接字地址。但在服务器端我使用:

IPEndPoint EndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8001);
TcpListener TcpServer = new TcpListener(EndPoint);
UdpClient UDPServer = new UdpClient(EndPoint);

也不例外。为什么?

我需要编写一个可以在同一端口上同时使用 TCP 和 UDP 协议的客户端。 TCP - 用于一般命令,UDP - 用于语音流。这该怎么做?

问题是我试图将 UDPClient 对象绑定到客户端和服务器端的相同端口号。这就是为什么我有一个例外。