×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

File transfer over sockets

File transfer over sockets

File transfer over sockets

(OP)
Hey guys,

I was wondering if someone could point me in the right direction with my project:

I'm to write a simple client and server programs that will use sockets. The client will be able to sent a GET <file name> command to the server and the server will send back the file (which does not have to be ASCII characters).

I have basic knowledge of sockets, so I can send text messages back and forth, but I can't  figure out how to transfer files.

Any help would be greatly appreciated!

RE: File transfer over sockets

If you want to use a library to do some of the grunt-work.
http://curl.haxx.se/

If you want to do it all yourself from sockets up, read
http://www.rfc-editor.org/rfc/rfc2616.txt
 

--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

RE: File transfer over sockets

(OP)
Thank you for your response,

I would like to write this program by myself, so I don't want to use the library.

Also, the paper on sockets that you linked me to doesn't have any examples that I'm looking for.

Let me describe my understanding of what I should do so far, so that someone could tell me if I'm on the right track:

1. At first, I need to establish a socket between the server and client
2. Set server socket to listen
3. Client will open a local file (.bmp lets say) using fread() and save the whole thing into buffer
4. Client then will write() the buffer into the socket
5. Server will accept() that buffer and using fwrite() it will recreate the bmp

Is this the right flow of action? Do I need to handle splitting the buffer into smaller pieces or will sockets handle that themselves?

RE: File transfer over sockets

> Also, the paper on sockets that you linked me to doesn't have any examples that I'm looking for.
That's not the job of the RFCs.  They tell you what to send (and what to expect in return), not how.

How is in "beej"
http://beej.us/guide/bgnet/

> Do I need to handle splitting the buffer into smaller pieces or will sockets handle that themselves?
A bit of both really.
You can send as much as you like, but you always have to deal with it not being able to send it all.  send() returns how many bytes were sent.  If that's less than the total, then try again with the remainder of the message until it's all gone.

Likewise at recv(), you can supply a large buffer, but you'll need to do some reassembly of the message.

Other than that, your approach looks OK so far.

--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close