Talking about computer network protocols UDP, TCP, Socket

A, TCP / UDP

TCP / UDP is a transport layer protocol (by divided into five layers: physical layer, data link layer, network layer, transport vehicles, the application layer)
. 1, the TCP is a connection-oriented transport of data security; the UDP is connectionless transmission data is insecure
2, TCP is a byte-oriented stream, UDP datagram-oriented
. 3, point to point connection-oriented TCP, UDP may be many
4, HTTP / HTTPS / FTP / SMTP network protocol based on the TCP, UDP-based network protocols are DNS / NFS / TFTP like
5, TCP header minimum length of 20 bytes, the maximum length of 60 bytes. Only 8-byte UDP

二、HTTP

HTTP is the protocol (Hypertext Transfer Protocol) application layer, he is to define how the browser how to communicate with the server and the communication data format. The relationship between HTTP and TCP are: HTTP connection is established on the basis of the TCP connection, TCP is simply to establish a connection, does not involve any actual data that we need to ask the simple transmission. HTTP is used to send and receive data, i.e., up to the practical application.

After establishing a TCP connection between the client and server application, you need to use the HTTP protocol to transmit data, the HTTP protocol is simple, that was a request to confirm the connection. C is generally sends an HTTP request to the S, S received this HTTP request, and then returns to CHTTP response, then C middleware or the browser to render the data pages become a showcase in front of the user.
In short: TCP connections are defined in the specification and the embodiment, HTTP is the definition of transmission of data content and form of

Three, Socket

Socket is a socket, the communication may be implemented between different virtual machine or on different computers, create Socket connection, can specify the transport layer protocol, may support different transport protocols Socket (TCP or the UDP), when a when the TCP protocol to connect the Socket connection is a TCP connection (TCP connection establishment in general are, in fact, is the "three-way handshake" operation), thus Socket connection once established, the two sides communicate with each other to start sending data content until disconnect the two sides. socket life cycle into three phases: open socket, send and receive data using a socket, close the socket, IO read and write operations is a thing, just socket receiving other written data and sends its written data (chat room is such a principle ).

Create a socket on the client side with: Socket socket = new Socket ( " IP address", port number);
create a server socket: ServerSocket server = new ServerSocket (port number);
            the Socket socket = server.accept (); // server back to the client side accpet message, returns a socket object in the queue.

Published 35 original articles · won praise 16 · views 190 000 +

Guess you like

Origin blog.csdn.net/qq_38795430/article/details/100852356