简体   繁体   English

静态IP对Java套接字编程重要吗?

[英]Is static IP important for Java socket programming?

I am confused about 127.0.0.1 and port no for socket programming. 我对127.0.0.1和套接字编程的端口号感到困惑。 If I a have a domain name then there is no importance of static ip address. 如果我有一个域名,那么静态IP地址就不重要了。 Anyone please help for this. 任何人都可以帮忙。

You can listen to a static IP-number directly if you want to, but normally in production a real web server such as Nginx or Apache is used for that, because they are faster, more secure, and handle headers and other parts of the HTTP standard for you. 您可以根据需要直接收听静态IP号码,但是通常在生产中使用诸如Nginx或Apache之类的真实Web服务器,因为它们速度更快,更安全,并且可以处理HTTP标头和其他部分您的标准。 They then in turn connect to your socket. 然后,它们依次连接到您的套接字。

127.0.0.1 is a special IP number also known as localhost, and is used to connect to the same machine, and is not accessible from other computers. 127.0.0.1是一个特殊的IP号,也称为localhost,用于连接到同一台计算机,并且不能从其他计算机访问。 So if you listen to 127.0.0.1 you need Nginx or similar on the same computer to forward traffic to your socket, otherwise it won't be accessible from other computers. 因此,如果您收听127.0.0.1,则需要在同一台计算机上使用Nginx或类似的设备将流量转发到套接字,否则其他计算机将无法访问它。

Socket Programming does not require that you only work with static IP address. 套接字编程不需要仅使用静态IP地址。 You can write code using localhost or 127.0.0.1 . 您可以使用localhost127.0.0.1编写代码。 If you know the domain name of server, you can use that as well. 如果您知道服务器的域名,也可以使用它。 You can also use the dynamic IP which most internet users get. 您还可以使用大多数Internet用户获得的动态IP。

Every computer connected to a network has an IP address assigned to it, whether statically or dynamically. 连接到网络的每台计算机都有一个静态或动态分配的IP地址。 A server socket must be bound to this IP address on a specific port in order to accept clients. 必须将服务器套接字绑定到特定端口上的此IP地址,才能接受客户端。 A client connects to the server's current IP and port. 客户端连接到服务器的当前IP和端口。

A domain name is simply a way for clients to determine the server's current IP address using a static human-readible name. 域名只是客户使用静态的可读名称来确定服务器当前IP地址的一种方式。 If the server's IP address changes, the server socket must be rebound, and the mapping of the domain name must be updated. 如果服务器的IP地址更改,则必须重新启动服务器套接字,并且必须更新域名的映射。

127.0.0.1, aka "localhost", is a reserved IP address that refers to the local machine. 127.0.0.1(也称为“ localhost”)是引用本地计算机的保留IP地址。 If a server socket is bound to this IP address, it can accept clients only from the same machine. 如果服务器套接字绑定到该IP地址,则它只能接受来自同一台计算机的客户端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM