Server:
#include <boost/serialization/vector.hpp>
struct someObject
{
int i;
template <class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & i;
}
}
struct OutStream
{
std::vector <someObject> someVector;
template <class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & someVector;
}
}outStream;
// Another part of the code
outStream.someVector.swap(someOtherVector);
// Serialise
std::stringstream archive_stream;
boost::archive::text_oarchive archive(archive_stream);
archive << outStream;
// Send
sendto(ServerSocket, archive_stream.str().c_str(), strlen(archive_stream.str().c_str())...
Client:
#include <boost/serialization/vector.hpp>
struct someObject
{
int i;
template <class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & i;
}
}
struct InStream
{
std::vector <someObject> someVector;
template <class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & someVector;
}
}inStream;
// Another part of the code
// Deserialize
archive_stream << temp;
boost::archive::text_iarchive archive(archive_stream);
ZeroMemory(&inStream, sizeof(inStream));
archive >> inStream;
someOtherVector.swap(inStream.someVector);
However when I run this, on the server side, either it doesn't send proberly(lots of blank variables) or it says
Expression:vector iterator not dereferencable[/quote]
If it would help I can upload the whole source code (it's not that large). Any help is much appreciated!
Thanks,
Rowan.