Results 1 to 5 of 5

Thread: Send std::map objet via TCP socket

  1. #1
    Join Date
    Jul 2015
    Posts
    2
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Send std::map objet via TCP socket

    Hello,
    I want to send an object std::map via socket tcp,,is this possible!!!
    Thanks in advance

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Send std::map objet via TCP socket

    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:
    1. Does your program absolutely need to manipulate a std::map, or can you replace it with a QMap?
    2. If you need a std::map, then write two generic functions to (de)serialize it to(from) a QDataStream.
    3. What are the key and value types of your map?
    4. Write the serialization/deserialization functions for QDataStream for those two types, if they do not already exist.

  3. #3
    Join Date
    Jul 2015
    Posts
    2
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: Send std::map objet via TCP socket

    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

  4. #4
    Join Date
    Nov 2014
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Platforms
    Windows

    Default Re: Send std::map objet via TCP socket

    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.

  5. #5
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Send std::map objet via TCP socket

    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?

Similar Threads

  1. To send A HTML File to my email using QTCP Socket
    By $ATHEES in forum Qt Programming
    Replies: 0
    Last Post: 4th September 2013, 08:56
  2. Replies: 2
    Last Post: 22nd May 2011, 21:31
  3. send & recuve via socket
    By nima in forum General Programming
    Replies: 4
    Last Post: 21st November 2010, 21:47
  4. PaintEvent() in a dynamically created and destroyed objet not working.
    By savaliya_ambani in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 20th October 2010, 08:49
  5. Replies: 7
    Last Post: 29th May 2009, 08:58

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.