开发者

Java ServerSocket. Why is the IP address 0.0.0.0, yet I can still connect remotely?

Now, I want to connect remotely, I just want to know why the server tells me it doesn't have an IP address.

Server started: ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=13380]

Relevant code:

private ServerSocket        serverSocket    = null;
private Thread              thread          = null;
private int                 clientCount     = 0;

/**
 * Constructor
 * 
 */
public Contro开发者_如何学运维lListener(int port)
{
    try
    {
        System.out.println("Binding to port " + port + ", please wait  ...");
        this.serverSocket = new ServerSocket(port);
        System.out.println("Server started: " + this.serverSocket);
        start();
    }
    catch (IOException ioe)
    {
        System.out.println("Can not bind to port " + port + ": " + ioe.getMessage());
    }
}

from link: http://pirate.shu.edu/~wachsmut/Teaching/CSAS2214/Virtual/Lectures/chat-client-server.html example 4 is what I followed


You bound to the any address which means you are listening on all interfaces. You can accept connections from that come in from any defined interface on the server including localhost and any IP addresses you have defined in case you are multi-homed.

You could bind to just 127.0.0.1 and only accept connections from localhost. You could bind to a specific IP address and only accept connections on that interface.


0.0.0.0 Means that all ips are being used. If you are trying to connect remotely, make sure you open up the port you are using in you firewall and/or router.


This is a wildcard, indicating that your socket will accept requests on every network adapter of your host.

You can restrict that behavior by defining a dedicated network adress upon construction.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜