Exchanging data using CSocket
-
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.
-
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.
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)); -
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));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.
-
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.
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).