Java 中的简单网络聊天
刚刚对我用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能是防火墙或路由器。
防火墙:端口未打开。
路由器:消息不会转发到托管您的应用程序的计算机。
或者您的应用程序使用的是内部 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)
如果您没有在代码中为不在内部网络上的计算机指定任何特殊内容,那么它不会以不同的方式处理它们。它本身不会以不同的方式处理连接。我会检查您(或他的)路由器并打开您使用的所有端口。
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.