开发者

How to debug java socket creation error

I'm trying to create a new socket, but it keeps finding a IO Exception, saying

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

Here is my code snippet:

  Socket mySocket = null;
  BufferedReader in = null;

try{
    mySocket = new Socket("localhost",4444);
    in = new BufferedReader( new InputStreamReader(mySocket.getInputStream()));
} catch (UnknownHostException e) {
    System.err.println("Don't know about host: localhost.");
    System.exit(1);
} catch (IOException e) {
    System.err.println("Couldn't get the I/O for " + "the connection to: localhost.");
    System.exit(1);
}

I tried to change m开发者_运维知识库y hostname "localhost" to also my hostname for my computer (i.e. typing in hostname in cmd to find hostname). Also tried another port, but it all keeps giving me the same error. What are some tips or ways to debug this? Or can you pinpoint what the problem is? Thank you for your help.


It means that no-one is listening to the port 4444 on your machine. Socket is the connector to channel that have 2 edges: sockets. Typically there is one ServerSocket on server side and Socket on client side.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜