how to write(implement) Application layer network protocol

I want to write(implement) a Application layer network protocol above TCP. Can you tell me how to start doing it? Any online tutorial will also be helpful guys i need sm implementation tutorial too. I am new to this and have less time also :( RFC is more about rules

asked Dec 29, 2010 at 18:10 2,935 9 9 gold badges 41 41 silver badges 54 54 bronze badges

4 Answers 4

Start by reading a standard for SMTP protocol. This is (originally) a very simple protocol with no strings attached and no confusing or bogus statements. HTTP and FTP are more complicated (for beginner) as they are more feature-rich, non-linear (in many aspects) etc.

Upd: I've put the link to the original RFC 821 , which is now obsolete. Yet it is much smaller and easier to read than the most recent (and valid) RFC for SMTP.

answered Dec 29, 2010 at 18:19 Eugene Mayevski 'Callback Eugene Mayevski 'Callback 45.8k 8 8 gold badges 73 73 silver badges 122 122 bronze badges

The best solution is to watch over current solutions like torrent, ftp, http. It should give you some knowlegde. Then disigned protocol will depend on your imagination.

answered Dec 29, 2010 at 18:12 1,615 9 9 silver badges 17 17 bronze badges

Designing your own protocol is no simple matter. However, building it on top of TCP/IP makes it easier. You pointed out that RFCs are rules about a protocol and you're right. However, that's generally what a protocol is: a set of rules and agreements of how something is to be done. The beauty here is that you get to specify your own rules. Some of the things you need to consider are the type(s) of data to be sent, the length of each piece, and state (if any). HTTP for example is a stateless protocol with a header that defines the request or result, and a payload defining the data being sent which could be a form post or an html page.

So you will need to define the data to be sent or received, the length of the data in bytes which can be defined by the datatype or the amount of data expected. If there is a state to your protocol - i.e. something must first be sent and received before something else can - then you need to define that state. Beyond that, it's simple network programming (sending and receive data in your application).

For example a simple protocol could have this:

Command 1 Byte Length 4 Bytes Data Length Bytes 

The first two define your header which contains metadata about the data the the other end needs to be able to read everything. The last would be the actual data. Command, though not necessary, serves to show that you can have the other side perform a specific action with the data depending on the byte received. The lengths of the data is important because the other end must know when it's read all of the data in before it can work on it.