Hello,
I want to send an object std::map via socket tcp,,is this possible!!!
Thanks in advance
Hello,
I want to send an object std::map via socket tcp,,is this possible!!!
Thanks in advance
The first thing you need is a way to serialize a map (compute a representation of the map as a stream of bytes) and deserialize it (rebuild the map from this representation). If I were you, I would first experiment with serialization/deserialization in memory; then I would worry about sending this sequence of bytes through a socket.
AFAIK there is no standard library support for (de)serialization. There are some well-established libraries to help you with this, such as Boost.Serialization. Or, if you can replace your std::map with a QMap, you can serialize it to/deserialize it from a QDataStream; all you need is to make sure the key and value types are (de)serializable.
Note that even if you use a std::map (and therefore need to implement (de)serialization code yourself), you could still serialize to a QDataStream, and benefit from its platform- and architecture-independent encoding of the basic C++ types.
So, to help you get started, here is a proposal with questions/things to do:
- Does your program absolutely need to manipulate a std::map, or can you replace it with a QMap?
- If you need a std::map, then write two generic functions to (de)serialize it to(from) a QDataStream.
- What are the key and value types of your map?
- Write the serialization/deserialization functions for QDataStream for those two types, if they do not already exist.
I sould you use C++ without Qt
So i peref to use std::map ans send <ked, data>
Do you have any idea how to reorganise received data from the client side!!
Form information I will send binaire image from the server to the cleitn
thanks in advance
This should work but only if message class is POD. If there are pointers or other not POD classes (string, vector) inside, it won't work.
Here are a few questions to help us understand the context.
- You wrote that you did not want to use Qt. What libraries are you working with?
- Are you only writing the program sending the std::map, or the receiver too?
- Does the data you send need to adhere to a specific format/protocol, or can you choose your own?
- What experience do you have with (de)serialization and network application development?
- What have you already tried to solve your problem?
Bookmarks