Socket programming question

Hi there ladies and gents, I'm busy with this client-server software and my question is "how are data packets identified between the client and server?". I know the question is a bit confusing so i'm gonna give an example. The first thing you do in this software is authentication (i.e. submit username and password from the client to the server.), now my problem comes when the server receives this data in a byte array, how does the server know what to do with the data and vice verse?
As you can imagine, there is more varying data that is going to be sent from the client to the server and the server must understand what is required of it and respond. I have some ideas on how to solve this problem but I was wondering if there is a conventional way to solve this problem.

Thanking you in advance.
the handshaking packets are marked as such and the connection library handles them.

for your own data, you must have a protocol that says what it is. This is almost always the first N bytes in the same format for all messages, usually 1-2 bytes that tie back to an enum in your code is sufficient for all but the most complex programs.

Transport Layer Security: https://en.wikipedia.org/wiki/Transport_Layer_Security

Libraries: https://en.wikipedia.org/wiki/Comparison_of_TLS_implementations

OpenSSL is non-cancerous (Apache-style license) and very portable;
works well across Unix, Windows and Unix-like platforms without requiring any platform specific code. https://www.openssl.org/
Last edited on
@jonnin, I thought of doing exactly that, thank you for confirming that I wasn't far off with my ideas.
@JLBorges, thank you for the info, I'm gonna take sometime to go though the articles. They seem to be very informative on how this should be done.
Topic archived. No new replies allowed.