Click to See Complete Forum and Search --> : Socket question


goon12
08-29-2002, 01:28 PM
I have searched high and low for help on this, but here goes:
I have beginner->intermmediate socket programming skills. I have written some simple client and server programs.. how ever I am looking to send a file through a socket. I am not sure if I can do that with sendto(), send() or am I way off? I would.

If someone could please point me in the right direction, I would appreciate it.

Thanks,
goon12

bwkaz
08-29-2002, 01:58 PM
From what I understand (which may not be accurate), you can't send a file through a socket directly. You have to read the file in, and write it to the socket, then have the other end read it off the socket. Which protocol are you trying to use? Just generic TCP, or something like FTP that's a layer on top of TCP? If you're not using straight TCP, then you have to know the semantics of the protocol you're using. If you are using TCP, then it's probably a good idea to either have a control connection open also (AFAIK this is what FTP does, but maybe not...), or have some "flag bytes" that won't ever be interpreted as part of a file -- one for "start file transfer", one for "end of file". Maybe more for "start filename" and "end of filename", so the remote host knows what to call it.

Edit: these flag bytes could just be sendto()'ed or send()ed (I know, that's horrible English, but oh well) as out-of-band stuff.

JohnT
08-29-2002, 01:59 PM
http://www.nsa.gov/selinux/doc/freenix01/node10.html

bastard23
09-03-2002, 01:23 PM
'man 2 sendfile'
sendfile - transfer data between file descriptors

Although it is non-portable, so be careful.

Good Luck,
chris