Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [SOLVED]Need Help:structure over socket
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Need Help:structure over socket

Scheduled Pinned Locked Moved Mobile and Embedded
23 Posts 6 Posters 14.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vahidnateghi
    wrote on 3 Nov 2013, 07:29 last edited by
    #21

    @struct your_structure
    {
    //variables
    },test@

    When you want to send the structure:
    @char * sendPack = (char *)&test;
    writeDatagram((const char *)sendPack,sizeof(your_structure),destIP,destPORT);@

    When you want to receive the packet:
    @char recPack[sizeof(your_structure)];
    readDatagram((char *)&inPack, sizeof(your_structure),senderIP, senderPort);
    your_structure * inp = new your_structure();
    inp = (your_structure *)inPack;@

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on 3 Nov 2013, 15:15 last edited by
      #22

      [quote author="vahidnateghi" date="1383463791"]@struct your_structure
      {
      //variables
      },test@

      When you want to send the structure:
      @char * sendPack = (char *)&test;
      writeDatagram((const char *)sendPack,sizeof(your_structure),destIP,destPORT);@

      When you want to receive the packet:
      @char recPack[sizeof(your_structure)];
      readDatagram((char *)&inPack, sizeof(your_structure),senderIP, senderPort);
      your_structure * inp = new your_structure();
      inp = (your_structure *)inPack;@[/quote]

      That won't work if you're on different architectures, like trying to communicate between a 32 bits and a 64 bits version of your application, to name just one possible problem with this approach. My advise: never, ever do it this way.

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vahidnateghi
        wrote on 4 Nov 2013, 05:30 last edited by
        #23

        [quote author="Andre" date="1383491720"]

        That won't work if you're on different architectures, like trying to communicate between a 32 bits and a 64 bits version of your application, to name just one possible problem with this approach. My advise: never, ever do it this way.
        [/quote]

        Yes,you're right, when I used it and it worked, it was between two machines with the same architecture...

        1 Reply Last reply
        0

        21/23

        3 Nov 2013, 07:29

        • Login

        • Login or register to search.
        21 out of 23
        • First post
          21/23
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved