Click here to Skip to main content
15,850,675 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, this is my first question on this website, hope I do good :)

so I'm new to c++ and started working on a project because I like to learn by doing, the project is made of two applications one client and one server and they communicate using sockets.

I want to write two functions to receive and send all data (big data, like files) from and to the socket.

I searched online for examples but couldn't find anything I understand, so I thought maybe I would ask for examples of the code online myself.


What I have tried:

I have tried different examples I found online, but couldn't get them to work together as they make my app hang. (also they seemed complicated)
Updated 17-Jun-22 0:53am

You could try ASIO[^]. It is somewhat difficult to grasp, at first. But there are many many working examples.
Share this answer
There lots of examples online: C++ tcpip - Google Search[^]. However if you cannot understand any of them then you probably need to focus on studying C++ in greater detail.
Share this answer
I don't have an exact solution for you because I have no idea what constraints you have to deal with. I can give you a tip though - use a little header structure to preface your data. It doesn't have to be very complex. I usually put the size of the data to be transmitted and a simple checksum that is easy to compute. I have done this many, many times and I find it makes things easier because you know exactly how much data to anticipate.

One of my applications runs multiple instances of itself and they all talk to each other and I built in a facility to allow it to send a copy of itself to another instance and to update itself there. It amounts to just another file transfer and then some dancing to shut down, copy, and restart itself but nothing terribly difficult. This transfer also uses a little header structure. Unfortunately, I haven't made that generic enough for easy reuse but I do that kind of thing every time I have to transfer any significant amount of data.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900