Java 中的简单网络聊天

发布于 2024-12-03 04:35:51 字数 183 浏览 1 评论 0原文

刚刚对我用 java 编写的一个简单的聊天程序有疑问。 该程序使用 TCP 在服务器/客户端之间来回传输简单的消息字符串。它适用于我网络上的所有计算机。但是当我将它发送给我的一个朋友以查看它是否可以在他的计算机上运行时,却不起作用。所以我的问题是:我是否需要添加一些特定的代码以允许接收来自我的网络外部的其他组件的消息?或者是某种防火墙阻止了这种情况?

just had a question to a simple chat program i wrote in java.
The program uses TCP to transmit simple message strings back and forth from Server/Client. And it works on all the computers on my Network. But when i sent it to a friend of mine to see if it worked from his computer it did not. So my question is: Would i need to add some specific code to allow messages from other comps from outside my network to be recieved? or is it some kind of Firewall that is preventing this?

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

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

发布评论

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

评论(2

山田美奈子 2024-12-10 04:35:52

可能是防火墙或路由器。

防火墙:端口未打开。

路由器:消息不会转发到托管您的应用程序的计算机。

或者您的应用程序使用的是内部 IP,而不是来自互联网的 IP(必须转发到您的内部 IP)

Probably a firewall or a router.

Firewall: port is not opened.

Router: message are not forwarded to the machine which hosts your application.

Or your application is using the internal IP and not the IP from the internet (which has to be forwarded to your internal ip)

烟凡古楼 2024-12-10 04:35:52

如果您没有在代码中为不在内部网络上的计算机指定任何特殊内容,那么它不会以不同的方式处理它们。它本身不会以不同的方式处理连接。我会检查您(或他的)路由器并打开您使用的所有端口。

If you don't specify anything special in the code for computers that's not on the internal network, then it won't handle them differently. It won't handle the connections differently by itself. I'd check your(or his) router and open any ports that you use.

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