0

I want to write (for the sake of learning) how to write a client-server app using C++. I have actually done it in the past and found many excellent tutorials on the web, including this good post on stack overflow:

How to write Client-Server application and implement simple protocol in Qt

What I would like to learn this time (and better understand) is how to actually write a protocol to communicate "meaningful" data between the client and server. Most examples just pass strings such as "Hello world". Great but not very practical.

What I would like to do is pass for example commands to the server that would modify some data (a document that the server would for example be responsible of keeping a copy of). I have been inspired after watching a video on Google Drive Real-Time in which they explain how the clients send commands like [insert, 10, "caterpillar"] to the server, which has for effect for example, to insert the chain of character "caterpillar" at index 10 in a string maintained by the server.

How would you send such commands typically in professional applications (how do you define them in the code, how do you pass them on, how to read them on the other end?)?

Bonus question;-): the video speaks a lot about data model. How does it relate to the protocol (the commands exchanged between the client and server and that allow them to understand each other)?

EDIT:

Actually found this question on Stackoverflow with some helpful answers:

Passing a structure through Sockets in C

What's the best way to serialize data in a language-independent binary format?

The solution seems to be called serialisation.

Community
  • 1
  • 1
user18490
  • 3,546
  • 4
  • 33
  • 52
  • Welcome to StackOverflow. Your post in its current form is too broad and not a good fit for Stack Overflow. Please visit the [help center](http://stackoverflow.com/help) and read the section [how do I ask a good question](http://stackoverflow.com/help/how-to-ask). – Captain Obvlious Sep 06 '16 at 17:22
  • I appreciate the feedback but would argue that my question is broad. There is no example of how to implement protocol to exchange data between a client-server apps on the net (not that I could find) and therefore I feel my question is precise and will serve the Stackoverflow community in the future. I am asking how this is done and eventually an example. – user18490 Sep 06 '16 at 17:27
  • Yes serialization idiom applies here but since there is no set standard way of doing what you want you have several options including various libraries. You're also asking how to define the data, how to send it, and how to receive it. Either one of the links you provided can be considered a duplicate of your post. – Captain Obvlious Sep 06 '16 at 18:10
  • Sure I will edit my post. I realised by "send" I don't mean how to use the `send()` command but how the data should be packed/unpacked. So it's probably confusing. I will mark the question as duplicate and post a link to the answers. – user18490 Sep 06 '16 at 18:51

0 Answers0