我試圖做一個非常基本的回聲服務器使用Java套接字,它完美地在本地工作(在同一臺計算機上同時運行服務器和客戶端),當我嘗試從另一臺計算機運行客戶端我得到異常:Java套接字,回聲服務器
Couldn't get I/O for the connection to XXX.XXX.XX.X
XXX.XXX.XX.X是本機的IP服務器在其上運行
BTW:我的代碼在服務器和客戶端都大致是的oracle初學者教程: server client
編輯: 完整的堆棧跟蹤我得到:
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)
端口是否打開並且未被防火牆阻止? – Kayaman
你能從客戶端機器ping通服務器機器嗎? – RealSkeptic
我想是這樣,因爲我用它來本地測試?或沒有 ?? – isco