Sending large chunks of data over Boost TCP?

boost, c++, network-programming, networking, tcp

Solution

Have you tried it with Boost's TCP? I don't see why 2MB would be an issue to transfer. I'm assuming we're talking about a LAN running at 100mbps or 1gbps, a computer with plenty of RAM, and don't have to have > 20ms response times? If your goal is to just get all 2MB from one computer to another, just send it, TCP will handle chunking it up for you.

I have a TCP latency checking tool that I wrote with Boost, that tries to send buffers of various sizes, I routinely check up to 20MB and those seem to get through without problems.

I guess what I'm trying to say is don't spend your time developing a solution unless you know you have a problem :-)

--------- Solution Implementation --------

Now that I've had a few minutes on my hands, I went through and made a quick implementation of what you were talking about: https://github.com/teeks99/data-chunker There are three big parts:

The serializer/deserializer, boost has its own, but its not much better than rolling your own, so I did.

Sender - Connects to the receiver over TCP and sends the data

Receiver - Waits for connections from the sender and unpacks the data it receives.

I've included the .exe(s) in the zip, run Sender.exe/Receiver.exe --help to see the options, or just look at main.

More detailed explanation: Open two command prompts, and go to DataChunker\Debug in both of them. Run Receiver.exe in one of the Run Sender.exe in the other one (possible on a different computer, in which case add --remote-host=IP.ADD.RE.SS after the executable name, if you want to try sending more than once and --num-sends=10 to send ten times). Looking at the code, you can see what's going on, creating the receiver and sender ends of the TCP socket in the respecitve main() functions. The sender creates a new PrimitiveCollection and fills it in with some example data, then serializes and sends it...the receiver deserializes the data into a new PrimitiveCollection, at which point the primitive collection could be used by someone else, but I just wrote to the console that it was done.

Edit: Moved the example to github.

Problem

I have to send mesh data via TCP from one computer to another... These meshes can be rather large. I'm having a tough time thinking about what the best way to send them over TCP will be as I don't know much about network programming. Here is my basic class structure that I need to fit into buffers to be sent via TCP: ``` class PrimitiveCollection { std::vector<Primitive*> primitives; }; class Primitive { PRIMTYPES primType; // PRIMTYPES is just an enum with values for fan, strip, etc... unsigned int numVertices; std::vector<Vertex*> vertices; }; class Vertex { float X; float Y; float Z; float XNormal; float ZNormal; }; ``` I'm using the Boost library and their TCP stuff... it is fairly easy to use. You can just fill a buffer and send it off via TCP. However, of course this buffer can only be so big and I could have up to 2 megabytes of data to send. So what would be the best way to get the above class structure into the buffers needed and sent over the network? I would need to deserialize on the recieving end also. Any guidance in this would be much appreciated. EDIT: I realize after reading this again that this really is a more general problem that is not specific to Boost... Its more of a problem of chunking the data and sending it. However I'm still interested to see if Boost has anything that can abstract this away somewhat.

Original source