Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Exchanging data using CSocket

Exchanging data using CSocket

Scheduled Pinned Locked Moved C / C++ / MFC
c++sysadmindata-structuresjsonhelp
4 Posts 2 Posters 0 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.
  • M Offline
    M Offline
    manoharbalu
    wrote on last edited by
    #1

    We have a Server and Client application developed in MFC The Server and the client exchange data using CSocket class We have a big Structure of size 900000 bytes to exchange data. Our Structure contains array of integer, char and float as data members. Our structure looks like the below eg. struct ModData { float LH [600]; float XS [30][600]; float NER [600]; float TDER [600]; float DER [30][600]; float SS [1500]; float SS2 [1500]; float COMP [30][1500]; char POIC [900]; int AMID [100]; char AMS [100]; char WTL [2500]; char FRN; char XGO; }; I am copying all the structure data to char variable and send and receive data between clients through serialization. We have a global object for the above structure whose values changes continuously based on some calculations every 250 millisec. So some of the data changes continously every 250 millisec. Example calculations that change data: Test->ss = Test->ss + Test->Log * Sin(5.62) * Test->LH /4.566 There are several formulas that get executed based on logics which process the data in cycles. I want to send only the values that are changing whereas now I am transfering the entire data every 2 seconds. Is there any better way of identifying only the changed data to send it. Please help.

    J 1 Reply Last reply
    0
    • M manoharbalu

      We have a Server and Client application developed in MFC The Server and the client exchange data using CSocket class We have a big Structure of size 900000 bytes to exchange data. Our Structure contains array of integer, char and float as data members. Our structure looks like the below eg. struct ModData { float LH [600]; float XS [30][600]; float NER [600]; float TDER [600]; float DER [30][600]; float SS [1500]; float SS2 [1500]; float COMP [30][1500]; char POIC [900]; int AMID [100]; char AMS [100]; char WTL [2500]; char FRN; char XGO; }; I am copying all the structure data to char variable and send and receive data between clients through serialization. We have a global object for the above structure whose values changes continuously based on some calculations every 250 millisec. So some of the data changes continously every 250 millisec. Example calculations that change data: Test->ss = Test->ss + Test->Log * Sin(5.62) * Test->LH /4.566 There are several formulas that get executed based on logics which process the data in cycles. I want to send only the values that are changing whereas now I am transfering the entire data every 2 seconds. Is there any better way of identifying only the changed data to send it. Please help.

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      Just define your own protocol by sending a header first. In this header you tell the other site which data will be send. Example:

      enum MyPacketData {
      AllData = 0,
      LhData,
      XsData,
      // ....
      };

      typedef struct {
      MyPacketData contentType;
      // Optional additional data
      } MyPacketHeader;

      // Send all data
      MyPacketHeader header;
      header.contentType = AllData;
      socket.Send(&header, sizeof(header));
      socket.Send(pData, sizeof(ModData));

      // Send specific data
      MyPacketHeader header;
      header.contentType = SsData;
      socket.Send(&header, sizeof(header));
      socket.Send(pData->SS, sizeof(ModData.SS));

      M 1 Reply Last reply
      0
      • J Jochen Arndt

        Just define your own protocol by sending a header first. In this header you tell the other site which data will be send. Example:

        enum MyPacketData {
        AllData = 0,
        LhData,
        XsData,
        // ....
        };

        typedef struct {
        MyPacketData contentType;
        // Optional additional data
        } MyPacketHeader;

        // Send all data
        MyPacketHeader header;
        header.contentType = AllData;
        socket.Send(&header, sizeof(header));
        socket.Send(pData, sizeof(ModData));

        // Send specific data
        MyPacketHeader header;
        header.contentType = SsData;
        socket.Send(&header, sizeof(header));
        socket.Send(pData->SS, sizeof(ModData.SS));

        M Offline
        M Offline
        manoharbalu
        wrote on last edited by
        #3

        Thanks for the Reply. Iam sorry that I didnt mention my query clearly. A Shared memory using CreateFileMapping function is created by the Server application to share the ModData with another process named 'Plantmodel' running local which does the most of the calculations. A GUI Client is also connected to the Server using sockets which gets the User inputs anytime. So the User gives an input anytime which is send to the server through sockets and the server updates the input in the shared memory and the plantmodel process which is already doing all the calculations in 250millisecs takes this input too. So at anypoint of time the real time data is available at the server. My actual question is...Is there anyway to find out only the data that is changed from the big structure from the server side, so that i could use a function to update it to the other client application instead of sending the entire data.

        J 1 Reply Last reply
        0
        • M manoharbalu

          Thanks for the Reply. Iam sorry that I didnt mention my query clearly. A Shared memory using CreateFileMapping function is created by the Server application to share the ModData with another process named 'Plantmodel' running local which does the most of the calculations. A GUI Client is also connected to the Server using sockets which gets the User inputs anytime. So the User gives an input anytime which is send to the server through sockets and the server updates the input in the shared memory and the plantmodel process which is already doing all the calculations in 250millisecs takes this input too. So at anypoint of time the real time data is available at the server. My actual question is...Is there anyway to find out only the data that is changed from the big structure from the server side, so that i could use a function to update it to the other client application instead of sending the entire data.

          J Offline
          J Offline
          Jochen Arndt
          wrote on last edited by
          #4

          It can be still done with my solution. Just send a message after each data update indicating whch data has been changed. If you need to track the changings, you may add another structure containing flags for the elements. However, in this case the flags must be cleared when the clients has processed the update (sending some kind of acknowledgement in the other direction).

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups