Hello....i am trying to send a file from server to the client using socket programming in C, how do i do this?? basically the client is trying to download a file from the server....

Recommended Answers

All 5 Replies

There are several online networking tutorials online (Beej is a good google term) - I'll assume that you have read these and will ask direct questions on points you do not understand.
The answer to your question, then, is that you

  • open socket, listen and accept the client connection
  • read from the client what file to serve
  • open the file on the server
  • read the file chunk by chunk
  • each chunk read from file should be written to the socket
  • close file
  • close socket

i understood the procedure to do it, but i am new to socket programming so i am looking for some code that helps me in transferring files....

i had already gone through beej's guide, but it doesn't describe about files anywhere in the book....


The examples on that site direct you how to send information over a network connection. To send a file, just open your file, read from it and write what was read to the network socket.

Specifically, look at this part and instead of the char * used in that code substitute the data from your file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.