i'm working on chat application in c# with a server coded in c++, i can already send and receive messages between my clients. But, my problem now, that a want to define the structure of the TCP packet by myself like :
[numberOfsequence: uint16_t] [id: uint16_t] [data: x] Where:
- numberOfsequence: is the number of my packet (to guarantee that in
receive the packets in order , i know that is automaticly regled by TCP protocol, but i wanna do it also) - id: represente the type of
operartion (login, message, disconnect) id is gonna be like 0000 for login , 0001 for message .... Data: information.
//TO connect TcpClient clientSocket; NetworkStream serverStream; clientSocket.Connect(IPAddress.Parse(textBoxIP.Text), Convert.ToInt32(textBoxPort.Text)); serverStream = clientSocket.GetStream(); //Sending login byte[] outStream = System.Text.Encoding.ASCII.GetBytes(textBoxLogin.Text); serverStream.Write(outStream, 0, outStream.Length); serverStream.Flush();
So my question is how to define the packet structure ? thanks