Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I have developed a server and client peer by the usage of socket programming in C# in windows. The server is TCP and it is able to handle multiple clients. So it is like a simple chat program.

I want to define and implement a new protocol over TCP in the communication between server and the clients.

The problem is I dont know how to wrap the packets in a new header.

Actually, before I have made a NTP client in C++ and therefore made the header with pack function in perl. But, in this project firstly I should do it in c# and secondly it is a chat server. Therefore, I used char variable for sending the messages NOT binary file.

So, the question is: How can I wrap all the packets of messages in a new header.

Would be really grateful if someone help me.

What I have tried:

I have googled it but could not find anything!
Posted
Updated 9-Nov-17 22:47pm

1 solution

You can add any information to a message as long as the server and all the clients understand how to interpret the extra data. So, for example, you could add an extra character at the beginning which identifies the type of message. You could add a group of characters that should be converted to an integer which gives the length of some special data, etc.
 
Share this answer
 
Comments
bamshad1986 10-Nov-17 4:57am    
Yes, but is it encapsulation? because each message will be divided to multiple packets. So it will be a header only for the first packet?
Richard MacCutchan 10-Nov-17 7:32am    
That was just a suggestion, how you actually design your protocol is up to you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900