Java 服务器套接字。为什么IP地址是0.0.0.0,但我仍然可以远程连接?

发布于 2024-10-12 11:59:34 字数 999 浏览 4 评论 0原文

现在,我想远程连接,我只想知道为什么服务器告诉我它没有IP地址。

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

相关代码:

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

/**
 * Constructor
 * 
 */
public ControlListener(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());
    }
}

来自链接: http:// Pirate.shu.edu/~wachsmut/Teaching/CSAS2214/Virtual/Lectures/chat-c​​lient-server.html 示例 4 是我遵循的

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 ControlListener(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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

人│生佛魔见 2024-10-19 11:59:34

您绑定到任何地址,这意味着您正在侦听所有接口。您可以接受来自服务器上任何定义的接口的连接,包括本地主机和您定义的任何 IP 地址(以防您是多宿主)。

您可以仅绑定到 127.0.0.1 并且仅接受来自本地主机的连接。您可以绑定到特定的 IP 地址并仅接受该接口上的连接。

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.

吹梦到西洲 2024-10-19 11:59:34

0.0.0.0 表示所有 ip 都被使用。如果您尝试远程连接,请确保打开防火墙和/或路由器中使用的端口。

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.

时光沙漏 2024-10-19 11:59:34

这是一个通配符,表示您的套接字将接受主机的每个网络适配器上的请求。

您可以通过在构建时定义专用网络地址来限制该行为。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文