简体   繁体   中英

Is static IP important for Java socket programming?

I am confused about 127.0.0.1 and port no for socket programming. If I a have a domain name then there is no importance of static ip address. 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. 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. 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.

Socket Programming does not require that you only work with static IP address. You can write code using localhost or 127.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.

Every computer connected to a network has an IP address assigned to it, whether statically or dynamically. A server socket must be bound to this IP address on a specific port in order to accept clients. A client connects to the server's current IP and port.

A domain name is simply a way for clients to determine the server's current IP address using a static human-readible name. If the server's IP address changes, the server socket must be rebound, and the mapping of the domain name must be updated.

127.0.0.1, aka "localhost", is a reserved IP address that refers to the local machine. If a server socket is bound to this IP address, it can accept clients only from the same machine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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