gpt4 book ai didi

c# - "Can´t open socket or connection refused"与 .NET

转载 作者:可可西里 更新时间:2023-11-01 02:36:48 25 4
gpt4 key购买 nike

当我尝试使用 netcat 将一些数据发送到我的服务器应用程序时,连接被拒绝。

服务器端:

IPAddress ip;
ip = Dns.GetHostEntry("localhost").AddressList[0];
IPEndPoint ipFinal = new IPEndPoint(ip, 12345);
Socket socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
socket.Bind(ipFinal);
socket.Listen(100);
Socket handler = socket.Accept(); ------> it stops here......nothing happens

最佳答案

问题已解决,我必须在数组中移动 1 个位置,因为第一个位置指向 IPv6 地址。

IPAddress ip;
ip = Dns.GetHostEntry("localhost").AddressList[1];
IPEndPoint ipFinal = new IPEndPoint(ip, 12345);
Socket socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
socket.Bind(ipFinal);
socket.Listen(100);
Socket handler = socket.Accept(); //------> it stops here......nothing happens

关于c# - "Can´t open socket or connection refused"与 .NET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2411671/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com