连接但不从 TcpListener 接收数据

发布于 2025-01-04 04:47:54 字数 776 浏览 2 评论 0原文

我开发了一个接收连接的小型服务器(基本上使用此处的示例:http://msdn.microsoft.com/en-us/library/system.net.sockets.tcplistener.aspx

问题是我不知道如何,但每当建立连接时,它就不能发送数据(或者发送的数据没有到达服务器,从 TcpListener 的 GetStream 读取 NetworkStream 的方法只是阻塞并且没有获取任何数据字节。

我尝试只是 telnet 它,而不是使用我拥有的客户端和问题是一样的。有趣的是,如果我执行“telnet localhost 2000”,它会完美地工作!

似乎有什么东西阻止了通信(以前甚至连 localhost 都无法工作,直到我升级了服务器上的 .NET Fw),但是我不知道会是什么,只是阻止数据但允许连接,实际上不知道应用程序可以做到这一点!

任何帮助都会非常感谢! 谢谢你!

编辑:

该行

TcpClient client = server.AcceptTcpClient();            

正确获取 tcp 连接,然后我获取网络流,当我尝试从中读取时,没有收到数据(i == 0):

i = stream.Read(bytes, 0, bytes.Length)

I have developed a small server that recives connections (using basically the example here: http://msdn.microsoft.com/en-us/library/system.net.sockets.tcplistener.aspx)

The problem is that i dont know how but whenever a connection is made, it cannot send data (or de data sent does not reach the server, the method Read of the NetworkStream from GetStream of the TcpListener just blocks and does not get any data byte.

I tried to just telnet it, instead of using the client i have and the problem is the same. The funny thing is that if i do "telnet localhost 2000" it works perfectly!!

It seems that something is blocking the communications (previously not even localhost was working until i upgraded .NET Fw on the server), but i dont know what can it be that just blocks the data but allows the connections, actually did not know than an application could do it!

Any help with this will be much appreciated!
Thank you!

EDIT:

The line

TcpClient client = server.AcceptTcpClient();            

Gets the tcp connection properly then i get the networkstream and when i try to read from it, there is no data received (i == 0):

i = stream.Read(bytes, 0, bytes.Length)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南风几经秋 2025-01-11 04:47:54

这是一个防火墙...显然端口 2000 上有一些具有特定协议的通用服务,并且防火墙阻止了所有不遵循此协议的数据:/

尽管如此,还是谢谢您的帮助!

It was a firewall... apparently there is some common service on port 2000 that has a specific protocol, and the firewall blocked all the data that was not following this protocol :/

Even though, thank you for your help!!

溺渁∝ 2025-01-11 04:47:54

您是否尝试使用 WAN IP 而不是 LAN IP 连接到您的服务器?
您可能需要转发路由器端口才能使其正常工作。

有关端口转发的帮助,请参阅此网站

Are you trying to connect to your server using a WAN IP instead of a LAN ip?
You may need to forward your router ports to make it work properly.

See this site for help concerning ports forwarding

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文