file transfer with sockets



I have googled to no avail on getting specifically what I'm looking for. I
have found plenty of full blown apps that implement some type of file
transfer but what I'm specifcally looking for is an example to follow for
using a tcp socket to transfer files between client/server, server/client.
Both server and client are my program so I'm not looking for how to
implement an FTP client, or how to download a file from a web server via
http etc... Protocol between my client/server is a simple command based
structure and I intended on it going something like this in english:

this example is client to server scenario but I'll implement on both ends..
so client/server can be server/client etc..
1) client requests a file from server
2) server verifies file exists and sends back an 'ok' with the files size
(or message saying no file exists)
3) client receives file's size and sends the 'ok' to start the transfer
4) server sends file / client receives file
5) client sends 'ok' after receive is done

I've given these steps here to be clear and specific on the part I'm trying
to learn how to do. I can do all steps here fine except step 4, the actual
send/receive of the file. Help on that would be greatly appreciated.

I'm not even sure if those specific steps will stay like that, I only used
them to narrow down the area of my question. Further, I'm looking to do this
with the sockets directly, using socket.send and socket.receive, (or their
async methods), as I've read elseware that is the most effecient way, as
opposed to using a networkstream object. Aside from help on the specific
task I'm trying to learn, any comments on which technique is a good choice
are also welcome (socket.send etc... networkstream object.. and I honestly
just saw a 'socket.sendfile' method in VS help before finishing drafting
this post... I'm posting anyway since I learn a lot from this forum, and
even if one of the higher level classes is a better choice, I want to learn
the socket way first.)




.



Relevant Pages

  • Re: Socket switch delay
    ... both at the client and at the server (and why ... would you set the send buffer size to zero on a non-overlapped ... One glaring error is your client does ... So when you use a single socket, ...
    (microsoft.public.win32.programmer.networks)
  • Re: Locking on async calls
    ... you must synchronize the entire SendMessage routine as an atomic ... operation to prevent mixed messages from being transmitted to the server. ... You are correct that read and write on the socket do not interfere with each ... If you want to handle multiple client connections from one server object ...
    (microsoft.public.dotnet.general)
  • Re: Design issue with WinSock/GetQueuedCompletionStatus
    ... delegate that to a shutdown routine called after all worker threads ... The application I've created is a server accepting connections on a few ... different TCP/IP ports and then lets the client run different commands. ... a TCP/IP socket can be closed for 2 different reasons: ...
    (microsoft.public.win32.programmer.networks)
  • Re: socket communication: socket doesnt connect
    ... Microsoft MVP, MCSD ... As far as your server code goes, ... accept the listening socket. ... Client client = new Client; ...
    (microsoft.public.vc.language)
  • Re: TCP server stop receiving new connections
    ... reset the event mask of your listening socket each time you ... I have a strange problem in my class library used by all our client ... server applications. ... incomming connections, but keeps current connections. ...
    (microsoft.public.win32.programmer.networks)

Loading