What should a packet look like?

Hi.
A more general question about network programming.
I'm trying to create a server/client messenger system just as a learning project and so, I'm wondering what should the exchange between the server and the client look like?
At this point, the way I did it is similar to the http GET string.
When the client needs to login, it sends a string in which the first char is a directive: for example, L for login, M for message, R for registration.
And then I have a key value pair separated by the & sign
For example, this string would look you in:
Lusername=bob&password=123456.

Is this anywhere the right way of doing it? Should I instead send XML data? or, how does this normally work?
You'll want _T(username=bob) for a start..
I'm trying to create a server/client messenger system just as a learning project and so, I'm wondering what should the exchange between the server and the client look like?
The key thing to remember is that TCP/IP is a stream protocol. That means, there are no end-of-record or continuation markers, you have to agree that yourself for the client and server.

For example, POP3 mostly uses a link per message. That is, messages are variable length and terminated by \n. Actually, the RFC says \r\n, but Unix MTA's accept \n.

Another example is HTTP. HTTP messages are mostly terminated with a blank line, that is, \r\n\r\n, unless the length can be specified up front. Further more, tokens are separated by a space, which is why you need this stuff.
http://www.w3schools.com/charsets/ref_utf_punctuation.asp

As you want to implement CHAT, you must agree how text is to be passed, how a message is terminated or can be identified by the other side, and what how you can add control messages over time.

At this point, the way I did it is similar to the http GET string.
When the client needs to login, it sends a string in which the first char is a directive: for example, L for login, M for message, R for registration.
And then I have a key value pair separated by the & sign
For example, this string would look you in:
Lusername=bob&password=123456.
That's ok, whatever you decide, just make sure the rules are flexible, then stick to them.

The problem with the web is that the rules may be described with some accuracy, but they aren't implemented universally, making working with web technologies similar to marking a 5 year old's homework.

Is this anywhere the right way of doing it?
Not really, you seem to be on the right track.

Should I instead send XML data? or, how does this normally work?
Keep things as simple as possible. When complexity needs to be introduced, place the extra burden on the features that need it--that's the key.

Good luck.
Topic archived. No new replies allowed.