How to write (implement) an application layer network protocol

I want to write (implement) an application level network protocol above TCP. Can you tell me how to start doing this? Any online tutorial will also be useful guys, I also need to complete a tutorial on implementing sm. I am new to this and have less time :( RFC is more about the rules

+4
source share
4 answers

Start by reading the standard for SMTP . This is (initially) a very simple protocol without string binding and no confusing or fictitious statements. HTTP and FTP are more complex (for beginners), since they are more multifunctional, non-linear (in many aspects), etc.

Update: I put a link to the original RFC 821, which is now deprecated. However, it is much smaller and easier to read than the most recent (and valid) RFC for SMTP.

+6
source

The best solution is to view current solutions, such as torrent, ftp, http. That should let you know. Then the written protocol will depend on your imagination.

+1
source

I would advise against doing this in C. There is a much simpler way to do this. Try a look at: www.twistedmatrix.com and look at your Python web infrastructure. If you can write C, you can certainly make Python without sweat. In addition, twisted takes care of most of the nastiness that is usually associated with network programming in lower-level languages ​​such as C.

0
source

Developing your own protocol is not easy. However, building it on top of TCP / IP simplifies its work. You have indicated that RFCs are protocol rules, and you are correct. However, as a rule, what is a protocol: a set of rules and agreements on how something should be done. The beauty here is that you can specify your own rules. Some of the things you need to consider are the type of data transferred, the length of each part, and the state (if any). HTTP, for example, is a stateless protocol with a header that defines the request or result, and a payload that defines the data to be sent, which can be a form message or an html page.

Thus, you will need to determine the transmitted or received data, the length of the data in bytes, which can be determined by the data type or the expected amount of data. If your protocol has a state - that is, something must first be sent and received before something else - then you need to determine this state. In addition, it is simple network programming (sending and receiving data in your application).

For example, a simple protocol might have the following:

Command 1 Byte Length 4 Bytes Data Length Bytes 

The first two define your header, which contains metadata about the data that the other end should be able to read everything. The last would be the actual data. The command, although not required, serves to show that you can force the other side to perform a specific action on the data depending on the byte received. Data lengths are important because the other end needs to know when it reads all the data before it can work on it.

This answer really helps reinforce what I am saying. Hope this helps! fooobar.com/questions/1333716 / ...

0
source

Source: https://habr.com/ru/post/1333713/


All Articles