0

I am trying to send 1kb of data from a "server" to a "client", but I just can't get it right. There are a few things that I NEED to do in this: 1) Need to use boost-asio sockets to transfer the data 2) Need to serialize a type I created (Packet) that will contain the data as a string or char*

Here is what is going on:

First, I get 1kb of data from a sample text file on the server. I get this and put it into the Packet type that I created. I have defined the data field in Packet to hold this data as a std::string. (I tried char* but it didnt work well - see next paragraph).

Second I serialize it using boost text_oarchive . I have no problems serializing the Packet type if it just contains a string, but what I really want is a way to serialize it with the data type being a char array (so that it works better with the socket below)

Third, I send it over a boost asio socket. Here I have a problem because I can't find a way to send a std::string over the socket connection. Everything I see as examples and in the documentation need a buffer using some type of char* and not a string.

its just a headache. can you help?

Sam Miller
  • 23,808
  • 4
  • 67
  • 87
jim
  • 95
  • 1
  • 1
  • 5

1 Answers1

0

Everything I see as examples and in the documentation need a buffer using some type of char* and not a string

That is correct, though it's quite simple to do using Boost.Serialization and Boost.Asio. You can serialize using a text_oarchive to a boost::asio::streambuf then send the resulting stream buffer contents using a socket.

See this question and my answer to that question for a more complete example.

Community
  • 1
  • 1
Sam Miller
  • 23,808
  • 4
  • 67
  • 87