“无法打开套接字或拒绝连接"与.NET [英] "Can´t open socket or connection refused" with .NET

查看:70
本文介绍了“无法打开套接字或拒绝连接"与.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Im getting a connection refused when I try to send some data to my server app using 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地址.

Problem solved, I had to move 1 position in the array, cause the first position points to an IPv6 address.

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

这篇关于“无法打开套接字或拒绝连接"与.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆