Java Network Programming (i) Networking basics

Source: Internet
Author: User

The purpose of network programming : to communicate with other computers directly or indirectly through network protocols.

  There are two main problems in network programming:

1. How to correctly locate one or more hosts on the network.

2. How to reliably and efficiently transfer data after locating the host.

At present, the more popular network programming model is the client/server (c/s) structure .

That is, the two sides of the communication as a server waiting for customers to request and corresponding. The customer requests the server when the service is required.

The server is always running, listening to the network port, once a customer request, will start a service thread to respond to the customer, while continuing to monitor the service window, so that later customers can also be timely service.

IP Address

Each host in the IP network must have a unique IP address, and the IP address is a logical address.

The Internet's IP address is globally unique.

  32-bit, four-byte, commonly dotted decimal format representation.

Example: 192.168.0.200

Protocol

  A rule, standard, or convention established for data Exchange (communication) in a network. (= semantic + syntax + rules).

Different tiers have their own different protocols.

Iso/osi Seven-layer Reference Model

The network architecture solves the heterogeneity problem by using the layered method , which divides the complex network interconnection into several smaller and single problems, and solves them on different layers.

  The OSI (Open System Interconnection) Reference model divides the different functions of the network into 7 tiers:

Application layer: Handling Network applications

Presentation Layer: Data representation

Session Layer: Inter-host communication

Transport layer: End-to-end connection

Network layer: Addressing and shortest path

Data Link layer: Media access (access)

Physical Layer: Binary transfer

  

  

  communication entities are not allowed to communicate directly between peers, each layer is a strict one-way dependency , the upper level (service user) using the services provided below, the lower layer (service provider) to provide services to the upper layer.

  The essence of Peer layer communication : the virtual communication between peer layer entities, the lower level provides services to the upper layer, and the actual communication is done at the bottom.

protocols used by the OSI layers:

Application layer: Telnet, FTP, HTTP, DNS, SMTP, POP3

Transport layer: TCP, UDP

TCP: A reliable connection-oriented transport protocol.

UDP: is a non-connected, unreliable transport protocol.

Network layer: IP, ICMP, IGMP

Port

Data transmitted over the Internet contains the IP address and port number that are useful to identify the destination.

  The IP address is used to identify the computer on the network, and the port number is used to indicate the application on that computer.

  A port is an abstract software structure (including some data structures and I/O buffers).

After an application establishes a connection (binding) to a port through a system call, the data passed to the port by the transport layer is received by the corresponding process, and the data sent to the transport layer is output by the corresponding process.

  The port is represented by an integer identifier, which is the port number.

The port number is related to the protocol, the TCP/IP transport Layer Two protocols TCP and UDP are completely independent of the two software modules, so the respective port numbers are also independent of each other, ports are often referred to as protocol port (Protocol port), referred to as port.

  The port is represented by a 16-bit number, and its range is 0~65535,1024 the port number below it to the predefined service. For example, HTTP uses port 80.

Data Encapsulation

One computer to send data to another computer, the data must first be packaged, and the process of packaging is called encapsulation .

  Encapsulation is the addition of a specific protocol header in front of the data.

In the OSI Reference Model, the unit of information exchanged between the peer layer protocol is called the Protocol Data unit (PDU, Protocol data unit).

Each layer in the OSI Reference Model relies on the services provided at the next layer.

In order to provide services, the lower layer of the PDU as the level of data encapsulation, and then added to the head (and tail) of the layer. The header contains the control information needed to complete the data transfer.

In this way, the process of data submission from top to bottom is essentially a process of encapsulation. The process of submitting from the bottom up to the destination is the process of continuous unpacking. As a matter of fact, the data transmitted on the physical line is actually encapsulated in a multilayer "envelope" outside.

 The purpose of network programming : to communicate with other computers directly or indirectly through network protocols.

  There are two main problems in network programming:

1. How to correctly locate one or more hosts on the network.

2. How to reliably and efficiently transfer data after locating the host.

At present, the more popular network programming model is the client/server (c/s) structure .

That is, the two sides of the communication as a server waiting for customers to request and corresponding. The customer requests the server when the service is required.

The server is always running, listening to the network port, once a customer request, will start a service thread to respond to the customer, while continuing to monitor the service window, so that later customers can also be timely service.

IP Address

Each host in the IP network must have a unique IP address, and the IP address is a logical address.

The Internet's IP address is globally unique.

  32-bit, four-byte, commonly dotted decimal format representation.

Example: 192.168.0.200

Protocol

  A rule, standard, or convention established for data Exchange (communication) in a network. (= semantic + syntax + rules).

Different tiers have their own different protocols.

Iso/osi Seven-layer Reference Model

The network architecture solves the heterogeneity problem by using the layered method , which divides the complex network interconnection into several smaller and single problems, and solves them on different layers.

  The OSI (Open System Interconnection) Reference model divides the different functions of the network into 7 tiers:

Application layer: Handling Network applications

Presentation Layer: Data representation

Session Layer: Inter-host communication

Transport layer: End-to-end connection

Network layer: Addressing and shortest path

Data Link layer: Media access (access)

Physical Layer: Binary transfer

  

  

  communication entities are not allowed to communicate directly between peers, each layer is a strict one-way dependency , the upper level (service user) using the services provided below, the lower layer (service provider) to provide services to the upper layer.

  The essence of Peer layer communication : the virtual communication between peer layer entities, the lower level provides services to the upper layer, and the actual communication is done at the bottom.

protocols used by the OSI layers:

Application layer: Telnet, FTP, HTTP, DNS, SMTP, POP3

Transport layer: TCP, UDP

TCP: A reliable connection-oriented transport protocol.

UDP: is a non-connected, unreliable transport protocol.

Network layer: IP, ICMP, IGMP

Port

Data transmitted over the Internet contains the IP address and port number that are useful to identify the destination.

  The IP address is used to identify the computer on the network, and the port number is used to indicate the application on that computer.

  A port is an abstract software structure (including some data structures and I/O buffers).

After an application establishes a connection (binding) to a port through a system call, the data passed to the port by the transport layer is received by the corresponding process, and the data sent to the transport layer is output by the corresponding process.

  The port is represented by an integer identifier, which is the port number.

The port number is related to the protocol, the TCP/IP transport Layer Two protocols TCP and UDP are completely independent of the two software modules, so the respective port numbers are also independent of each other, ports are often referred to as protocol port (Protocol port), referred to as port.

  The port is represented by a 16-bit number, and its range is 0~65535,1024 the port number below it to the predefined service. For example, HTTP uses port 80.

Data Encapsulation

One computer to send data to another computer, the data must first be packaged, and the process of packaging is called encapsulation .

  Encapsulation is the addition of a specific protocol header in front of the data.

In the OSI Reference Model, the unit of information exchanged between the peer layer protocol is called the Protocol Data unit (PDU, Protocol data unit).

Each layer in the OSI Reference Model relies on the services provided at the next layer.

In order to provide services, the lower layer of the PDU as the level of data encapsulation, and then added to the head (and tail) of the layer. The header contains the control information needed to complete the data transfer.

In this way, the process of data submission from top to bottom is essentially a process of encapsulation. The process of submitting from the bottom up to the destination is the process of continuous unpacking. As a matter of fact, the data transmitted on the physical line is actually encapsulated in a multilayer "envelope" outside.

Java Network Programming (i) Networking basics

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.