我正在开发一个小型 TCP 客户端/服务器库。
我在创建客户端并将其连接到服务器时遇到了这个问题。它给了我这个异常(exception)
每个套接字地址(协议(protocol)/网络地址/端口)通常只允许使用一次
我的代码是。
public TCPClient(string remoteIPAddress, int port)
{
this.remoteIPAddress = IPAddress.Parse(remoteIPAddress);
this.port = port;
IPEndPoint remoteEndPoint = new IPEndPoint(this.remoteIPAddress, this.port);
tcpClient = new TcpClient(remoteEndPoint);
}
这里是 TCPServer
public TCPServer(int listeningPort)
{
this.listeningPort = listeningPort;
tcpListenter = new TcpListener(this.listeningPort);
workers = new List<TCPServerWorker>();
this.keepRunning = false;
}
我得到这个异常的任何帮助
最佳答案
已解决。
我用过
tcpClient = new TcpClient();
tcpClient.Connect(remoteIPAddress, port);
关于c# - TCP 套接字错误 : Only one usage of each socket address (protocol/network address/port) is normally permitted,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1905230/