简体   繁体   English

Java套接字,回显服务器

[英]Java sockets, echo server

I'm trying to do a very basic echo server using java sockets, it works perfectly locally(running both the server and client on the same computer), when I try to run the client from another computer i get the exception : 我正在尝试使用java套接字做一个非常基本的回显服务器,它在本地完美运行(在同一台计算机上同时运行服务器和客户端),当我尝试从另一台计算机运行客户端时,出现异常:

Couldn't get I/O for the connection to XXX.XXX.XX.X

XXX.XXX.XX.X being the IP of the machine on which the server is running XXX.XXX.XX.X是运行服务器的计算机的IP

btw : my code for both the server and the client is roughly that of the oracle beginner tutorials : server client btw:我为服务器和客户机编写的代码大致都是oracle初学者教程: 服务器 客户机的代码

EDIT : The full stacktrace I get : 编辑:我得到的完整stacktrace:

java.net.ConnectException: Connection timed out: connect at java.net.DualStackPlainSocketImpl.connect0(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) at java.net.AbstractPlainSocketImpl.connect(Unknown Source) at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.<init>(Unknown Source) at java.net.Socket.<init>(Unknown Source) at sockets.Client.main(Client.java:16)

As mentioned in the comments, the two used computers were hooked on two different wifi suppliers. 如评论中所述,两台二手计算机挂在了两个不同的wifi供应商上。 An answer to a similar question mentions possible other reasons. 对类似问题的回答提到了其他可能的原因。

I get the exception 我例外

    Couldn't get I/O for the connection to XXX.XXX.XXX.XXX

That is not an exception. 也不例外。 It is a poorly designed error message that conceals the exception. 这是设计不良的错误消息, 掩盖了异常。 When you get an exception, don't display/print/log a meaningless error message of your own devising. 遇到异常时,请勿显示/打印/记录您自己设计的无意义的错误消息。 Display/print/log the exception itself, and its message, and its class, and its stacktrace. 显示/打印/记录异常本身它的消息它的类它的堆栈跟踪。

EDIT: The full stacktrace I get: 编辑:我得到的完整stacktrace:

    java.net.ConnectException: Connection timed out: connect

Exactly. 究竟。 This is the real exception, and it almost certainly means there is a firewall preventing you from making the required connection. 这是真正的例外,几乎可以肯定,这意味着有防火墙阻止您进行所需的连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM