当前位置: 动力学知识库 > 问答 > 编程问答 >

java - connection refused exception in socket programming

问题描述:

In simple socket programming in java , what ip should be given while making new socket and its on wan

//Server side

ServerSocket ss = new ServerSocket(8888);

System.out.println("\n\n\tWaiting for connection\n");

Socket c = ss.accept();

System.out.println("\n\n\tConnection established\n");

//Client side

Socket c=new Socket("192.16*****",8888);

System.out.println("\n\n\tSuccessfully connected to the server");

//in **** there is complete ip address of my computer .... i.e. IPV4 address (checked

//from ipconfig command on cmd)

网友答案:

By default, a new ServerSocket should bind to all network interfaces. You should be able to find out what interfaces are being used by running (I assume you're running Windows, since you mentioned ipconfig):

netstat -an |find /i "8888"

If in fact the application is creating a socket and binding to all interfaces, you should see an entry like the following:

TCP   0.0.0.0:8888   0.0.0.0:0   LISTENING

Otherwise, you should be able to get the interface that is being used (it's the first IP address from the left).

分享给朋友:
您可能感兴趣的文章:
随机阅读: