c# - TCP 套接字错误 : Only one usage of each socket address (protocol/network address/port) is normally permitted

标签 c# sockets tcp

我正在开发一个小型 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/

相关文章:

c# - 使用 C# 抓取 directx 程序的屏幕

c# - Web.Config 键值

c# - 将位图图像转换为矩阵

c - getaddrinfo 删除最后一个字符

c++ - 担心处理对 accept() 的错误调用

c - TCP接收问题

c# - .NET 7 将文件模式映射到静态文件服务

python - 如果超时则跳过 URL

改变方向的 Android TCP 连接

java - 数据传输无法使用 ObjectOutputStream.writeObject()