Java socket programming (1) basic terms and concepts

Source: Internet
Author: User
ArticleDirectory
    • 2. Group packets
    • 3. Protocol
    • 4. Address
    • 5. Domain Name System (DNS) and local configuration database
    • 6. clients and servers
    • 7. What is socket)

ComputerProgramBeing able to communicate with the Internet makes everything possible. This is also the basis for the existence of the Internet today. So how does a program communicate with each other through the network? That's why I recorded the series of notes. The Java language was designed for the Internet from the very beginning.Many useful APIs are provided to implement program communication. These application programming interfaces are called sockets). Before learning about Java Socket, we need to first understand the basic terms and concepts.

1. Computer Network

Computer NetworkBy a groupCommunication Channel)A group of interconnected machines. These machines are called:Host (hosts)AndRouter (routers):

  • Communication Channel-- It is a means of transmitting byte sequences from one host to another (wired, wireless (WiFi), etc ).
  • Host-- The role is to run the program's computer.
  • Vro-- Transmits or forwards information from one communication channel to another.

TCP/IP network communication flowchart:

2. Group packets
  • Group message --Byte sequences created and interpreted by programs in the network environment.
3. Protocol

ProtocolIt is equivalent to an agreement for mutual communication. The Protocol specifies the Packet Exchange methods and their meanings.

The protocol used by the Internet isTCP/IP protocol, TCP/IP protocol familyIt mainly includes:

  • IP protocol(Internet protocols)
  • TCP protocol(Transmission Control Protocol)
  • UDP protocol(User datasync Protocol)

IP protocol

  • IP protocol-- Is the only one in TCP/IP protocolNetwork Layer. Transfers data from one host to another.
  • IP protocol-- Provides a data service: The packets in each group are processed and distributed independently by the network.It is similar to sending a mail or package through the postal system.
  • IP protocol-- Is"Do your best"(Best-effort) Protocol: it tries to distribute packets in each group. during network transmission, packet loss occasionally occurs when the packet order is disrupted or packets are repeatedly sent.

The transport layer is above the IP protocol layer. It provides two Optional Protocols: TCP and UDP.The two protocols are based on the services provided by the IP layer. They are also called "end-to-end Transport Protocol) "data is transmitted in different ways according to different application protocols. Both have a common function: addressing.The port number used by TCP and UDP is used to distinguish different applications on the same host.

TCP protocol

TCP protocolIt can detect and recover possible packet loss, duplication, and other errors from the host to the Host channel provided by the IP layer. TCP is a connection oriented protocol. before using it for communication, a TCP connection must be established between two applications, this involves handshake message exchange between the TCP components of two interconnected hosts.

UDP protocol

UDP protocolIt does not try to fix the Errors generated by the IP layer. It simply expands the IP protocol and "best effort" Data Service so that it can work between applications rather than between hosts. UDP-enabled applications must be prepared for packet loss and disordered order processing.

4. Address

In the TCP/IP protocolThe following information is used to locate a specified program: Internet address and port number (range: 1-65535). The former is used by the IP protocol, and the latter is parsed by the transmission protocol (TCP/UDP.

An Internet address consists of binary numbers in either IPv4 (32-bit) or IPv6 (128-bit ). For ease of use,Two versions of IP protocolThere are different Representation Methods:

  • IPv4 addressIt is represented as a group of four decimal numbers separated by dots. This representation is called the dotted-quad ).
  • IPv6 addressThe 16 bytes are represented by several hexadecimal numbers separated by semicolons. Each number represents two bytes in the address.

Loop address

Loopback address is a special loopback interface allocated. The loopback interface is a virtual device and its function.Simply return the packet sent to it to the sender immediately.. For example, 127.0.0.1 in IPv4

5. Domain Name System (DNS) and local configuration database

DNS is a distributed database.It maps domain names such as www.baidu.com to real Internet addresses and other information. The DNS protocol allows hosts connected to the Internet to obtain information from the DNS database through TCP or UDP protocol.

Local configuration databaseGenerally, a mechanism related to a specific operating system is used to map local and Internet addresses.

6. clients and servers

The terms client and server represent two roles:

  • ClientIs the initiator of the communication, andServer programThen passively wait for the client to initiate a communication and respond to it.
  • ClientAndServerConstituteApplications.
7. What is socket)

A socket is an abstraction layer through which an application sends and receives data, just as an application opens a file handle and reads and writes data to a stable storage.

The main socket types in the TCP/IP protocol family are:

  • Stream socket): The transport layer uses the TCP protocol to provide a reliable byte stream service.
  • Datagram socket): The transport layer uses the UDP protocol to provide a "best effort" datagram service. It can send up to 65500 bytes of data at a time.

 

References: TCP/IP socket in Java

author : Sunny pig

source : http://www.cnblogs.com/IPrograming

the copyright of this article is shared by the author and the blog. You are welcome to repost it. However, you must keep this statement without the author's consent and provide a connection to the original article on the article page, otherwise, you are entitled to pursue legal liability.

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.