|
-
March 27th, 2009, 06:24 AM
#1
Sending data over SOCKETS (serialization)
Hi,
I am trying to send an array of objects over a socket using winsock. Obviously I can't send the array in its current form and need to somehow convert it to an appropriate format. I have heard of the following "ideas" - serialisation, and converting to a byte array.
Would anyone be able to give me a quick example of how I might approach this, considering that the array we wish to convert is an array called products of type ProductInfo:
ProductInfo products[10];
I will be sending the eventual data via: send(client, senddata, (int)strlen(senddata), 0 );
David.
-
March 27th, 2009, 06:55 AM
#2
Re: Sending data over SOCKETS (serialization)
Came across the following stuff, which does work, but I want the character representation, not the file. Is there something similar???
ofstream out("binary.txt", ios::binary);
out.write((char*)&products, sizeof(products));
out.close();
ProductInfo test[10];
ifstream in("binary.txt", ios::binary);
in.read((char*)&test, sizeof(test));
cout << test[2].get_make();
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|