Fundamentals of Java Network programming

Source: Internet
Author: User

/*
* 1.IP Address: InetAddress Object
*The identity of the device in the network.
* Memory, available host name.
* Local loopback address: 127.0.0.1, hostname: localhost.
* 2. Port number: You have objects
*The identity of the different processes used to identify the logical address of the process.
*Valid ports: 0~65535, where the 0~1024 system uses or retains ports.
* 3. Transfer Protocol:
*Rules for communication.
* Common protocol: TCP,UDP.
* UDP: (QQ chat, video lessons)
* The data and the source and the target are encapsulated into a packet without the need to establish a connection.
* The size of each packet is limited to within 64k.
* Because there is no connection, it is an unreliable protocol.
* No need to establish a connection, fast.
* TCP: (QQ voice, video)
* Establish a connection to form a channel for transmitting data.
* Make large data transfers in the connection.
* Connecting via three handshake is a reliable connection protocol.
* The connection must be established and the efficiency will be slightly lower.
* 4.Socket provides a mechanism for network services.
* Sockets are available at both ends of the communication.
* Network communication is actually the communication between sockets.
* Data is transmitted via IO between two sockets.
*
*/



/*

* Network Programming:
*1 Network Model:
*OSI Reference Model:
*TCP/IP Reference Model:
* 2. Network communication elements:
* IP Address:
* Port number:
*Transport protocol:
*3. Define the communication rules:
*Language is different, communication needs rules, this rule is called protocol.
*The international organization defines the universal protocol TCP/IP.
*4. Two computer communication: Find the other IP, the data to be sent to the other side of the specified application, in order to identify these applications
* program, so to these network applications are used array to identify, in order to conveniently address this number, called "Port." Logical port.
*
*/
Import java.net.*;
public class Inetaddressdemo {
public static void Main (string[] args) throws Exception {
Get host
InetAddress I=inetaddress.getlocalhost ();
Gets the native name and IP address.
System.out.println (I.gethostname () + "---" +i.gethostaddress ());
Get the name or IP address of the other machine, the parameters inside the getbyname can make the hostname, IP address, domain name.
InetAddress ia=inetaddress.getbyname ("www.baidu.com");
System.out.println (Ia.gethostname () + "---" +ia.gethostaddress ());
}
}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Fundamentals of Java Network programming

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.