JAVA notes: Java Network Programming (1) IP and InetAddress,

Source: Internet
Author: User

JAVA notes: Java Network Programming (1) IP and InetAddress,

Java supports the development of the network communication system. It mainly provides two communication protocols:

TCP: reliable transmission protocol, which uses three-way handshake to complete communication

UDP protocol: Unreliable transmission protocol, which is not necessarily received by the receiver during transmission

Java contains all the network program development classes in the java.net package.

IP address related knowledge belongs to the computer network content, related Introduction: http://baike.baidu.com/link? Url = MmVDEtnaE5l2iT1-FW0WEp22g0nELwHIWd1yN0H0fah896wPlfJR2zk9x5JZd9BT956uao0vSrTBE56qv_4S9q


The Inetaddress class mainly represents the IP address. This class has two sub-classes: Inet4address class and Inet6address class. One Class represents the IPV4 protocol, and the other class represents the IPV6 protocol.

Common Inetaddress methods:


Instance:
Import java.net. inetAddress; public class InetAddressDemo {public static void main (String args []) throws Exception {// All exceptions throw InetAddress locAdd = null; InetAddress remAdd = null; locAdd = InetAddress. getLocalHost (); // obtain the local remAdd = InetAddress. getByName ("http://www.baidu.com/"); System. out. println ("local IP Address:" + locAdd. getHostAddress (); System. out. println ("Baidu IP Address:" + remAdd. getHostAddress (); System. out. println ("local availability:" + locAdd. isReachable (5000 ));}};


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.