W
W
winser2014-01-03 18:53:47
Programming
winser, 2014-01-03 18:53:47

How to pass and receive C++ variables over the network?

I wrote a client-server based on winsock2 in c ++
Everything works fine, but I transfer the data in the form of SQL queries and I have to send one message and then wait for a response from the server and so on several times.
Are there any standard solutions to pass variables of different types, including std::string, from one c++ program to another?
You can, of course, create a message yourself to come up with some kind of separator, then write the reception of this message on the other side, but it seems to me that there have been standard solutions for this for a long time.
Plus, when passing strings, there is always a chance that the transmitted string will be the same as the separator I invented.
I am interested in maximum simplicity, and it is desirable in the future without problem docking with other programming languages, that is, I send it to C ++, for example, I receive it in C #.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
P
Pavlo Barmak, 2014-01-03
@kynisa

XML For with ++ there was a question here.
JSON For c++ was also here.

T
Trrrrr, 2014-01-03
@Trrrrr

In order not to think what to use json or xml, I recommend looking at boost::ptree.
It's a wrapper over some standard data storage formats.
Here is a small tutorial:
www.boost.org/doc/libs/1_42_0/doc/html/boost_prope...
write_json instead of write_xml and you can use another format (although there are nuances, but they are not important here)

A
afiskon, 2014-01-03
@afiskon

winsock2 and c++ are old school, of course, but in the third millennium it is customary to use REST , or some Protobuf for example.

W
winser, 2014-01-03
@winser

SQL has nothing to do with it, the task is simply to accept and receive variables over the network in one message.
I am unfamiliar with serialization, I think this is the whole question

W
winser, 2014-01-03
@winser

In general, there is a lot, but we need a working example of receiving and transmitting data
to JSON or XML !!!
some functions that will write variables on one side and read them on the second
. And so far, apart from the description of the data format, I have not found anything, and it takes too long to implement everything myself.
If there is nothing ready in C++, then it is easier to make your own separator and check that the value of the variable does not contain this separator.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question