0

I want to send a file in C++ over network (for a chat program) what should I do?

JGC
  • 12,737
  • 9
  • 35
  • 57
  • 1
    see http://stackoverflow.com/questions/2014033/send-file-in-socket-programing-in-linux-with-c-c – Idan K Jan 19 '10 at 07:37

5 Answers5

4

Take a look at http://www.boost.org/doc/libs/1_38_0/doc/html/boost_asio/examples.html . The Iostreams example should give you the first good step. Asio is a portable network library of the boost project. Boost is available for most platforms available today.

You can stream in the file and stream out it into the TCP stream.

Damg
  • 406
  • 3
  • 9
1

Use Open source FTP library for more robust application .Read this thread for c++ based open soruce library.

Community
  • 1
  • 1
Satbir
  • 6,358
  • 6
  • 37
  • 52
  • I couldn't disagree more. FTP has a lot of inherent problems (especially nowadays with all the NATs in the way) and certainly should be avoided for new applications. – avakar Jan 19 '10 at 08:58
1

Its quite easy. Set up a TCP/IP socket and then split the file into packets and send them across. TCP is reliable thus all the packets will arrive in the right order and it will handle re-transmission etc.

If, however, you need to use an unreliable transport (such as UDP) then look at stop and wait (Easiest), go-back-n or selective repeat (Which are both somewhat harder but far more efficient).

Goz
  • 61,365
  • 24
  • 124
  • 204
0

You can open a direct connection between the two and send the content the file. For that, one side will be the client and the other will be the sender.

You can see a simple implementation here.

Amirshk
  • 8,170
  • 2
  • 35
  • 64
0

You will be doing something called socket programming. Please refer Beej's Guide to Networking for all the details and the solution to your problem.