The OSI seven-layer model is a standard system and framework for interconnection between different computers or communication systems, including a range of standards and protocols in OSI, such as TCP/IP, UDP, HTTP, and so on, which provide implementation and support for these protocols in Node.js, such as: NET modules provide TCP, Socket encapsulation and support, the Dgram module provides a package and support for UDP, the HTTP module further encapsulates the TCP protocol provides HTTP support. This paper gives a brief introduction to the implementation module of the related protocols, concepts and node.js in the network, followed by the specific Introduction module and its function article. The implementation and support of OSI seven-layer model Node.js to network protocol
1. OSI seven-layer model
1.1 Concept Introduction
OSI (open System Interconnection) Open Systems Interconnection Reference Model, ISO developed a standard system for the interconnection between computers or communication systems, it is a seven-layer abstract model, from low to high, namely: physical layer, Data link layer, network layer, transport layer, session layer, The presentation layer and the application layer. The aim is to provide a common foundation and standard framework for the interconnection of different computers, including a series of abstract terminology, concepts, and specific protocols, which can be used to interconnect computers or communication systems in accordance with the OSI Reference Model and related protocols.
Brief introduction of 1.2 OSI seven-layer model Application Layer (Application Layer):The application layer is an interface between network service and end user, whose function is to exchange information between application process (such as user program, terminal operator, etc.). Application layer protocols are: HTTP, FTP, TFTP, SMTP, SNMP, DNSPresentation Layer (presentation Layer):The presentation layer is used for the control of data representation, whose main function is to transform the information provided by the application layer into a common understanding form, and to provide a unified representation of character code, data format, control information format, encryption, etc.conversation Layer (session Layer):The session layer is the control layer of the session unit, which is used to establish, manage and terminate the session, whose main function is to collect and send the data according to the principle of the agreement between the application processes, and to carry on the dialogue of various forms in the correct order. The session layer provides a protocol for the establishment and removal of session connections between session service users and data transfer rules.Transport Layer (transport Layer):The transport layer defines the protocol port number for transmitting data, as well as flow control and error parity. For the data transfer control layer between systems, the main function is to send and receive data between open systems. At the same time, it is also used to make up the quality difference of various communication networks, to restore the transmission errors after the three layers, and further improve the reliability. The session Layer protocol has: TCP, UDPNetwork layer (network Layer):Logical address addressing, to achieve the choice between different networks, for packets or packets through the communication subnet to select the most appropriate path. Control the information forwarding between the data link layer and the transport layer, establish, maintain and terminate the network connection. Network layer protocols are: ICMP, IGMP, IP, ARP, RARPData Link Layer (Layer):Data link can be roughly understood as a data channel, the main function of this layer is: through a variety of control protocols, the error of the physical channel into error-free, reliable transmission of data frames data link. Its function includes: establishes the logical connection, carries on the hardware address addressing, the error efficacy and so on.Physical layer (physical Layer):The physical layer is not the physical medium itself, it is simply an open system to use physical media to achieve physical connection function description and implementation of the connection procedures. The physical layer provides the mechanical, electrical, functional, and process conditions for establishing, maintaining, and disconnecting physical connections, such as establishing, maintaining, and disconnecting physical connections. The physical layer protocols are: Rs 232C, Rs 449/422/423 and so on.
2. Node.js to the network protocol implementation and support
2.1 Net module with TCP, Socket
TCP and Socket
TCP (Transmission control Protocol) Transmission Control Protocol, is a connection-oriented, reliable, byte-throttling transport layer communication protocols, located on the IP protocol, TCP is the Internet Transport layer protocol, using three handshake protocol to establish the connection, and terminating a connection takes four shakes. TCP provides a transport mechanism for the application layer, for example: HTTP works on TCP, and many other connection-oriented applications (such as IRC, SMTP, IMAP) also work on TCP.
Socket is a layer of abstraction between the application layer and the transport layer, which abstracts the complex operation of TCP/IP layer into several simple interfaces, and the process of communication is realized in the network, the socket itself is not the protocol, is the encapsulation of TCP/IP protocol, is a calling interface.
node.js Net module
The Node.js provides a net module that provides encapsulation and support for TCP, sockets, and includes methods for creating TCP servers/clients. NET module inherits from the events and stream modules, the server/client created by the module is also an event emitter, and the client socket socket object that it creates is a read-write stream. NET Module network operation of the basic modules, node.js other network operations related modules, such as: HTTP modules, are based on the further encapsulation of the net module.
NET model for more information, please refer to: Node.js to tcp/socket implementation of the net module use.
2.2 dgram module and UDP
UDP user datagram
The UDP (user Datagram Protocol) Datagram Protocol is a connectionless transport layer protocol. It is the same as the TCP protocol above the IP protocol, and is also located at the transport layer, for processing packets. However, TCP protocol is a link-oriented, providing reliable and orderly data transmission between network nodes. The UDP protocol is a connectionless protocol and does not have the reliability of TCP protocol. UDP stateless features are especially useful in some cases, such as broadcast and multicast messages. Applications that use UDP include: DNS, streaming media applications, IPTV, network voice, and so on.
Node.js's Dgram module
Node.js uses the Dgram module to support the UDP User Datagram protocol, which is relatively lightweight because it does not have to be connection-oriented like TCP. To send or receive a UDP message, you can use the Dgram module to create a socket object that sends messages to other UDP terminals. After you bind a socket object to a UDP port, you can listen for incoming messages. The UDP module also implements the events module, but unlike the TCP socket object, the module does not inherit the stream module.
Dgram model For more information, please refer to: Node.js User Datagram Dgram module.
2.3 HTTP module and HTTP
HTTP protocol
HTTP (hypertext Transfer Protocol) Hypertext Transfer Protocol, an application layer protocol for content transmission, is one of the most widely used network protocols on the Internet, it works on TCP and is the basis of the World Wide Web for data communication. The most notable feature of the HTTP connection is that every request sent by the client requires a server response, and the connection is automatically released when the request is completed.
HTTP modules for Node.js
You can use HTTP modules to easily create HTTP servers or HTTP clients in Node.js, which is a secure version of the HTTPS module. HTTP modules are built on top of the net module, so most of the functionality in the Net module can be used in HTTP modules. Like the Net module, the HTTP module also implements events and stream modules, and the HTTP module creates objects that are either event emitters or read-write stream, or both event emitters and stream. For a detailed description of the HTTP model, please refer to the HTTP Module Overview of Node.js HTTP module. For a detailed description of the HTTPS model, refer to: Create an HTTPS server using the Node.js HTTPS module.