开发者

Protocol design for an application

I am writing an client server application. In this I will have to transfer packets of size 1024 bytes from the client to server. If the packet size is more it must divided into two packets. The server has to understand if the received packet is a new packet or continuation of the old packet. Then it should contain version number of the protocol. This protocol can be used by multiple application so the packet should also contain the application identifier to determine which application. The packet should also contain the crc info to check the error in the packet. Can any one suggest me a design for the above protocol to communicate between client and server. 开发者_开发问答 Can any one suggest me some tutorials which would explain how data will be encrypted and sent from the client and then received and decoded in server.


A protocol is something which is exchanged on mutual understanding. The details of the protocol defines how reliable and mission critical your application is.

The way of implementing a simple protocol is simply embed the frame size in the beginning of the packet. Also the data can be async received as chunk of files. It's simple logic to seperate them and add to the processing queue. If you've a fixed size, rather sharing the size, simply read each 1024 frames and consider it as your frames. A simple counter will help for this right?


Apart from the basic info you would need to introduce some sort of sequence numbering scheme indicating the continuation number (0 for the first packet) so that the server can understand the difference between a new stream of packets and data from the previous stream and also reorder them if there is out of order delivery.

Now you don't have to do all this if you are designing a real world application since you would just pick TCP/IP for a reliable transaction and if you check the details of that it handles all the cases you are talking about. But incase you do have to design a smaller protocol what I recommend would be create a small state diagram of your protocol to check whether all paths lead to some final states (a protocol state machine), it is easy to miss some cases otherwise

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜