INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

HANDLE


PASSWORD
Remember Me
Forgot Password?

Come Join Us!

  • 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!

E-mail*
Handle

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

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Member Feedback

"...I wish I knew about this site years ago. It would have saved me a lot of heartaches..."

Geography

Where in the world do Tek-Tips members come from?

 File transfer over sockets

thepain009 (TechnicalUser)
1 Mar 09 10:00
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!
Salem (Programmer)
1 Mar 09 10:21
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.

thepain009 (TechnicalUser)
1 Mar 09 13:19
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?
Salem (Programmer)
1 Mar 09 15:16
> 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.

Start A New Thread

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

Click Here to join Tek-Tips and talk with other members!

Promoting, selling, recruiting and student posting
are not allowed in the forums.
Posting Policies

LINK TO THIS FORUM!
(Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum)
TITLE: C Forum at Tek-Tips
URL: http://www.tek-tips.com/threadminder.cfm?pid=205
DESCRIPTION: C technical support forum and mutual help system for computer professionals. Selling and recruiting forbidden.

 

Back To Forum