Thread: How to transfer data structures over net ?

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    111

    How to transfer data structures over net ?

    Howdy ,
    I'm working on a project that the server will be developed using C and run on linux , while the clients will be running on mobile phones and small pc's .

    This is a study project (to learn QT embedded and more) so here is the deal .
    I need to transfer data structures from the server to clients ,

    I read about soap while it looked fine i realized it is abit problematic (over kill) i played abit with transferring structures using network sending but here the serialization issue arises.

    Thanks in advance ,
    why Gaos didn't had a wife ?
    http://bsh83.blogspot.com

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    Perhaps the QDataStream is suited to your needs?

  3. #3
    Registered User Maz's Avatar
    Join Date
    Nov 2005
    Location
    Finland
    Posts
    194
    i would use tcp or udp sokets. Just remember that in embedded world people often use big endianess targets, and when negotiating with pc, one needs to handle conversions.

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    when you do not know possible OS/language on the receiving size - serialization is best approch IMHO

    you do not need to serialize to xml though, text string with suitable separators is enough...

    just make sure that choosen separators could not be part of the data on any locale settings

    For example I would not use . or , as separators as they could be part of the number string representation

    if your data could include date/time - symbols like \ / : - # are also out of the scope
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I agree, the most obvious solution is to simply make the data into a text-string and transfer that. It solves all problems with byte-order, padding and sizes of data types that commonly happen when one tries to transfer data across the net.

    Another option to "avoid anyting that could be part of your content" is to use a quoted or escaped method. For example, we use : as a separator. Strings that may contain : will have to be quoted (using either single 'xxx' or double quotes "xxx"), or escapted, for example using the C style convention of a backslash: The text "15:45" then converts to "15\:45". Obviously, just like C, backslash itself also needs to be escaped.

    Even if you use XML, you will need some way to describe things that are part of the XML syntax (such as < and >).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User Maz's Avatar
    Join Date
    Nov 2005
    Location
    Finland
    Posts
    194
    Oh, so we were talking about protocols, sorry. If the amount of sent structures is fixed, it is possible to build send\recv with simple method. Append each sent struct with the size. Add some identification number to structs. Fix the endianess to certain format, or add the endianess info to the beginning of message.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 06-16-2005, 10:03 AM
  2. array of structures, data from file
    By nomi in forum C Programming
    Replies: 5
    Last Post: 01-11-2004, 01:42 PM
  3. data transfer
    By Blaster in forum Linux Programming
    Replies: 4
    Last Post: 03-12-2003, 08:10 AM
  4. speakers
    By Unregistered in forum C Programming
    Replies: 12
    Last Post: 03-31-2002, 08:57 AM
  5. different sized data structures
    By breed in forum C Programming
    Replies: 3
    Last Post: 03-04-2002, 02:00 PM