Answer the question
In order to leave comments, you need to log in
Communication protocol of a client-server program?
There are two C++ programs: a server and a client. They need to exchange fairly simple textual information. What are the best practices to implement? Now I just pass lines in which the first digit before the dot is the message identifier, and then the data is already parsed depending on the type of message.
Answer the question
In order to leave comments, you need to log in
Already noted above: JSON or XML. From myself, I can add that JSON will be a little better in terms of efficiency (much less redundant service information), but XML can be validated using schemas written for individual requests. There is also BSON, which is even more efficient than JSON, and, for example, ProtocolBuffers (http://code.google.com/p/protobuf/). The choice should depend on the specifics of the client-server connection.
Well, it is desirable to write a sort of framework for requests / responses, so it will be easier to work. For example, for a request, the required fields may be a number, request time, protocol version and some payload, which will change depending on the type of request.
Thanks everyone for the replies. I just recently learned about ProtocolBuffers, so I'll probably try with it first.
If the data is strongly typed and strongly structured, then Protobuf. If the format is not very strict, then JSON is a better fit.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question