473,395 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Class data to byte stream transfer mechinisim

I'm working with a bunch of configuration data that needs to be sent over
from a workstation to a server. The old method was to simply memcpy
structures into a buffer and send that across, however now I'm trying to
use variable sized classes and coming into some difficulty in the copying
data to a bytestream without going too crazy. So I ask, what are your
experiences/suggestions/help with doing the following:
(Pointing me to other documetation, or new nifty libraries is fine)
#include <vector>
#include <memory>

class A {
public:
int aa;
int bb;
};

class B {
public:
std::vector<A*> aList;
void insert(A *element){
aList.push_back(element);
}
};

char Lan_Data[1000];

void workstation(){
A a1,a2;
B b;

a1.aa=10;a1.bb=20;
a2.aa=30;a2.bb=40;

b.insert(&a1);
b.insert(&a2);

//Now, copy data of 'b' (no matter how many elements)
//into a char buffer (Lan_Data) to send to a socket

// TBD:????
}

void server(){
B b;
//Take data from Lan_Data and load up the 'b' element.

// TBD:????
}

int main(){
memset(Lan_Data,0,sizeof(Lan_Data));
workstation();
server();
return 0;
}
Sep 24 '05 #1
3 2042
You should not use A's pointer in aList. try to define vector<A>
aList which will contain the whole object instead of obejct's pointer.
you also need to define a copy
construct function if object includes members of pointers

Sep 24 '05 #2
Babbit wrote:
I'm working with a bunch of configuration data that needs to be sent over
from a workstation to a server. The old method was to simply memcpy
structures into a buffer and send that across, however now I'm trying to
use variable sized classes and coming into some difficulty in the copying
data to a bytestream without going too crazy.


this may be of interest
http://www.parashift.com/c++-faq-lit...alization.html
--
Nick Keighley

Sep 24 '05 #3

Babbit wrote:
I'm working with a bunch of configuration data that needs to be sent over
from a workstation to a server. The old method was to simply memcpy
structures into a buffer and send that across, however now I'm trying to
use variable sized classes and coming into some difficulty in the copying
data to a bytestream without going too crazy. So I ask, what are your
experiences/suggestions/help with doing the following:
(Pointing me to other documetation, or new nifty libraries is fine)
#include <vector>
#include <memory>

class A {
public:
int aa;
int bb;
};

class B {
public:
std::vector<A*> aList;
void insert(A *element){
aList.push_back(element);
}
};

char Lan_Data[1000];

void workstation(){
A a1,a2;
B b;

a1.aa=10;a1.bb=20;
a2.aa=30;a2.bb=40;

b.insert(&a1);
b.insert(&a2);

//Now, copy data of 'b' (no matter how many elements)
//into a char buffer (Lan_Data) to send to a socket

// TBD:????
}

void server(){
B b;
//Take data from Lan_Data and load up the 'b' element.

// TBD:????
}

int main(){
memset(Lan_Data,0,sizeof(Lan_Data));
workstation();
server();
return 0;
}


You could encode the structures using using BER (Binary Encoding Rules)
(see ASN.1). There are numerous implementations available.

You could also encode the structure as XML, send it over, and then
rebuild it on the other side by parsing the XML. Actually this
suggestion just repackages the first one. In both cases the receiver
would be able to recreate the original data structures, without knowing
their structure beforehand.

Greg

Sep 25 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sunny | last post by:
Hi all, I'm creating client/server app in C# (VS. 2003). So, I need the client to call the server with some auth info (user and pass). If the auth is OK, server will do some work and will prepare...
17
by: bengamin | last post by:
Hi, I have a C# class and two instance of the class; the class have some property. I want to compare the property value of the two instance How should i do? override == ? use delegate ?
1
by: sfoxover | last post by:
Hi, Could someone please give me some suggestions on how to make this class robust. I need to be able to handle around 20 similtanious requests to this class which causes a web browser to...
3
by: Ste | last post by:
Hi group, having done some searching on Google i have managed to save an instance of my class to a database by first serializing it to a file. The question i have is: can i do this without...
6
by: | last post by:
Hi all, is there a better way to stream binary data stored in a table in sql 2005 to a browser in .net 2.0? Or is the code same as in .net 1.1? We noticed that in certain heavy load scenarios,...
9
by: craig.overton | last post by:
All, I am currently developing an FTP class in VB.NET. It's kid tested, mother approved when trying to access an FTP Server on a Windows box meaning I can connect, run commands, upload and...
0
by: shapper | last post by:
Hello, I followed some examples in internet and in MSDN web site to create a serializable class. Basically, I need to serialize a class to binary so I can save it in an SQL 2005 table using a...
2
by: MDANH2002 | last post by:
Hi From VB.NET I want to simulate the POST request of the following HTML form <html> <title>HTTP Post Testing</title> <body> <form action=http://www.example.com/postdata ...
3
by: Stephen Torri | last post by:
Below is a class that is suppose to represent a segment of memory or a contents of a binary image (e.g. ELF executable). I have started to read Modern C++ Design and thought the best way to ensure...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.