Java programming Those things 107--network protocol concept

Source: Internet
Author: User
Tags split

13.2.5 Network protocol

For programmers who need to engage in network programming, a network protocol is a concept that requires deep understanding. So what is a network protocol?

Network protocol is the provision of data format for transmission in the network. For Web programming beginners, there is no need to understand the TCP/IP protocol cluster, so for beginners to read the big "TCP/IP protocol" is not a very appropriate thing, because the in-depth understanding of TCP/IP protocol is the network programming improvement phase, but also deep network programming at the bottom of the things to do.

For the general network programming, more is concerned about the network transmission of logical data content, that is, more is the application layer of network protocol, so the subsequent content is based on the actual application of the data to introduce the concept of network protocol.

So what is a network protocol, and here's a simple example. Spring Festival Party "small Shenyang" and Zhao Benshan cooperation of the sketch "Not bad Money", small Shenyang and Zhao Benshan between the design of an agreement, the content of the agreement is:

If the order price is more expensive, say no.

In accordance with the provisions of this Agreement, there is the following dialogue:

Zhao Benshan: 4 kg of lobster

Little Shenyang: (After judging, the price is higher), no

Zhao Benshan: Abalone

Little Shenyang: (After judging, the price is higher), no

This is a kind of agreement agreed between the two sides, in fact, the essence of this agreement is the same as the essence of the network protocol. The essence of the network protocol is also the client program and server-side program for the data of a convention, but because of the computer, so more is the use of numbers to represent content, so it seems more abstract.

The following is a simple example to introduce some basic knowledge of network protocol design. For example, you need to design a simple network program: the network calculator. That is, the client inputs the numbers and operators that need to be computed, implements the calculation on the server side, and feeds the results of the calculation back to the client. In this example, you need to contract two data formats: The data format that the client sends to the server, and the data format that the server feeds back to the client.

Perhaps you think this is relatively simple, such as the number of client input is 12 and 432, the input operator is a plus, the most likely to think of the data format is the formation of a string "12+432", so that the format is really easier to read, but the server in the calculation, the logic is more trouble, Because you need to split the string first before you can compute it, there are several data formats available:

The "12,432,+" format is: the first digit, the second number, the operator

The "12,+,432" format is: the first number, the operator, and the second number

In fact, the above two types of data format is very close, easier to read, the server side received the data format, the use of "," for the delimiter split string.

Suppose there is a second convention for the operator, for example, the contract number 0 represents +,1, 2 represents multiplication, and 3 represents addition, the overall format follows the first format, then the above digital production protocol data is:

"12,432,0"

This is a basic protocol to send.

Another need to design the protocol format is the server-side feedback data format, in fact, the server side of the main feedback calculation results, but in the actual acceptance of data, there may be a malformed situation, so you need to design a simple server-side feedback data format. For example, if the data sent is in the correct format, the feedback string is "wrong". This allows you to have the following data formats:

Client: "1,111,1" server-side: "-110"

Client: "123,23,0" Server side: "146"

Client: "1,2,5" Server side: "Error"

This is the design of a most basic network protocol format, from this example, you can see that the network protocol is a format of the agreement, you can according to the needs of the logic of a variety of data formats, in the design generally follow the "simple, general, easy to resolve" principle.

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.