Ip0.0.0.0

Source: Internet
Author: User
A Special IP Address: 0.0.0.0 is equivalent to this in Java and represents the IP address of the current device. In Java programming, we use serversocket for network listening. Generally, we only need the following code: serversocket serversock = new serversocket (8888); serversock. accept (); if my host IP address is 10.10.152.8, you can use the above Code to listen. 127.0.0.1: 8888 or 10.10.152.8: 8888 can be connected, but have you ever thought about it, which IP address is used by this serversocket for listening? If we change the above Code to explicit binding: serversocket Ss = new serversocket (); string IP = "10.10.152.8"; int Port = 8888; inetsocketaddress ADDR = new inetsocketaddress (IP, port); SS. BIND (ADDR); SS. accept (); you will find that 127.0.0.1: 8888 cannot be accessed. If you change the IP address to 127.0.0.1, then 10.152.8: 8888 cannot be accessed. In fact, the secret behind it lies in the IP address 0.0.0.0, which can represent all the IP addresses of the local machine, but this IP address does not actually exist. We cannot ping it. If we change the IP address to 0.0.0.0: serversocket Ss = new serversocket (); string IP = "0.0.0.0"; int Port = 8888; inetsocketaddress ADDR = new inetsocketaddress (IP, Port); SS. BIND (ADDR); SS. accept (); we will find that this is the same as the default behavior, 127.0.0.1: 8888 or 10.10.152.8: 8888 can be connected.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.