InetSocketAddress中的通配符地址是什么意思? [英] What does wildcard address in InetSocketAddress mean?

查看:150
本文介绍了InetSocketAddress中的通配符地址是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在构造函数的文档中 InetSocketAddress(int port) 它说:

In the docs for the constructor InetSocketAddress(int port) it says:


创建一个套接字地址,其中IP地址是通配符地址
,端口号是指定值。

Creates a socket address where the IP address is the wildcard address and the port number a specified value.

通配符是什么地址做什么以及在 socket.bind()中使用它意味着什么?

What does a wildcard address do and what does it means when used in socket.bind()?

推荐答案

来自文档:通配符是一个特殊的本地IP地址。它通常表示任意,只能用于绑定操作。

From the docs: The wildcard is a special local IP address. It usually means "any" and can only be used for bind operations.

此IP地址的值为0.0.0.0。如果您有两个网络适配器,一个IP地址为1.1.1.1,另一个IP地址为2.2.2.2,那么您可以创建一个侦听套接字并将其绑定到1.1.1.1,以便套接字不会绑定到2.2.2.2。您还可以创建一个侦听套接字并将其绑定到2.2.2.2,以便它不会绑定到1.1.1.1。如果你不在乎并希望你的套接字绑定到所有网卡,那么你将它绑定到通配符地址。

The value of this IP address is 0.0.0.0. If you have two network adapters, one with IP address 1.1.1.1 and one with IP address 2.2.2.2, then you can create a listening socket and bind it to 1.1.1.1 so that the socket will not bind to 2.2.2.2. You can also create a listening socket and bind it to 2.2.2.2, so that it will not bind to 1.1.1.1. If you do not care and want your socket to bind to all network cards, then you bind it to the wildcard address.

另一个特殊值是127.0.0.1,意思是只有同一台计算机上的客户端才能连接到您的服务器。

Another special value would be 127.0.0.1, meaning that only clients on the same computer could connect to your server.

这篇关于InetSocketAddress中的通配符地址是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆