1 Attachment(s)
Simple Winsock client/server file uploader demo.
Recently I've seen a few about questions sending data using Winsock across a network and a lot of the times people have trouble figuring out when their data has been fully sent/received or if there is more. TCP/IP being a streaming protocol, doesn't lend itself well to this. My answer is to implement your own scheme to do this over TCP/IP. It usually involves sending a length prefix along with the data so the receiver can count the bytes to determine when it has received all the data.
The attached applications are a client application and a server application that can transfer a file between them. The client application sends the file and the server receives the file and saves it to a configurable location. I've set default values that should allow you to test the programs right away on the same machine using the loop back adapter.
You must start both applications and click the "listen" button on the server and then you click the "connect" button on the client application and the status bars of both application should read "connected" if it succeeds. From there you click the "upload" button on the client application and select a file using the dialog that pops up. The client should begin the upload after selecting a file. I recommend using a large file to see the progress. Any file of 100 MB or more should be sufficient. The loopback and even LAN is very fast so small files will be transferred instantly.
Note: These applications were created using Visual Studio 2010 so you would need that or later to open the projects.
On last thing. The apps are not meant to be usable. They are made to demonstrate the basic idea behind creating your own protocols for data transfer. In an effort to keep it as simple as possible I didn't add too many complexities to it. The sever is limited to being able to accept one connection and there can only be one file transfer at a time. It cannot in its current state transfer multiple files at the same time. Also, I did not put too many error traps so expect that if you push it by doing weird things, it will crash.
Feel free to ask any questions about it. Any suggestions to improve it will also be welcomed.
Re: Simple Winsock client/server file uploader demo.
Deleted...
I replied in the wrong thread!
Sorry...