F
F
fralik2011-05-12 12:20:26
Programming
fralik, 2011-05-12 12:20:26

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

6 answer(s)
S
Shizz, 2011-05-12
@fralik

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.

C
Co0l3r, 2011-05-12
@Co0l3r

JSON, XML

A
antivir, 2011-05-12
@antivir

I would first of all look towards XML-RPC.

F
fralik, 2011-05-12
@fralik

Thanks everyone for the replies. I just recently learned about ProtocolBuffers, so I'll probably try with it first.

D
dutchakdev, 2011-05-12
@dutchakdev

I'll put in my 19 cents.
I would use JSON.

D
dborovikov, 2011-05-13
@dborovikov

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 question

Ask a Question

731 491 924 answers to any question