0

I have created my client-server application but there is still something confusing about the whole process. What is packets? and what is the difference between sending a packet and sending a message (like i normally do).

So please, I expect a good explanation about:

  1. What is packets?
  2. How to structure them?
  3. How to use them for communication in my client-server application?
Shakti Prakash Singh
  • 2,414
  • 5
  • 35
  • 59
Daniel Eugen
  • 2,712
  • 8
  • 33
  • 56

1 Answers1

2

For the sender and on a higher level a packet is equivalent to a message, you send packets or messages. On the receiving side a message may be split up into multiple packets. This splitting is most common using TCP connections, where you might have to do more than one receive-call (each returning a "packet") to receive a complete message.

To make matter more confusing, on a lower level a single TCP or UDP message (with TCP/IP headers prepended to the data) can also be called a packet. And on an even lower level an ethernet frame may be called a packet as well.

And to confuse even more, TCP connections has no real concept of message, it's just a stream of bytes. Messages are just an artificial concept on top of TCP. UDP on the other hand are distinct messages.

In short, it's probably simplest to just keep on using the term "message" when referring to the data you send or receive.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • But you just more confused me i want to know how to properly send message from client to server and know which message i received from the server – Daniel Eugen Sep 18 '12 at 16:18
  • How to use packet id and packet type, please give me an example of how to send a packet from server and receive it on client – Daniel Eugen Sep 18 '12 at 16:19
  • 1
    @DanialEugen Just send it! What you are sending, when should send it, how you format it and how you differ between one message and the other, that's totally up to you. Some protocols are stateless (like the HTTP) and are strictly request/response without caring about the order of the messages. And if you worry about order then use TCP, as that protocol _guarantees_ that the "messages" will arrive in the order you send them. The terminology doesn't really matter on the application level, but the term "message" is probably the most used. – Some programmer dude Sep 18 '12 at 17:23
  • Sorry but what made me ask this question that i was sending a message normally using Encoding.ASCII.GetBytes("ID:MESSAGE"); then on the server using Encoding.ASCII.GetString(Buffer); and use .Spilit(':'); to get the message id. But someone told me this is a silly way and just confused me at all – Daniel Eugen Sep 18 '12 at 17:30
  • Can you give me a small portion of your time to explain me the whole thing in chat ? – Daniel Eugen Sep 18 '12 at 17:38