views:

196

answers:

1

I have a simple file sharing application. Users are sending data among each other via packets of size 1024 KB. Everything works perfectly, but what I need next is header for each packet. I'm not completely sure that I understand the concept of a header, but I believe it should contain information such as: username of the user that has the file, size of the file, name of the file so that the user that is downloading the file can be sure he is downloading the right file.

Any example or link would be most welcome as this is the first time I'm dealing with this type of thing.

+1  A: 

The purpose of a header is to convey information about the package that follows the header. For the sake of argument, consider a file transfer application such as the one you are developing, where for instance a file can be transferred from several users at the same time to a user that wants the file. If each sender sends a packet containing a part of the file, you will need some form of information about which part this is - for instance a sequence number or an offset into the file so that the receiver is able to put the pieces together to the actual file.

To make it easy for yourself, you can take a look at Google Protocol buffers, which allows you to specify what fields make up the messages as well as serialize and deserialize them.

You can find examples of things to put in a header in the TCP protocol for instance, although you shouldn't think that you need everything that is in that header or something like that. Looking at other protocols are a good way to learn though.

villintehaspam