I am building a data backup application in C# using Sockets. It has a server component and a client component. The client is going to upload files to the server through TCP sockets. I've got all figured out and have been able to transfer files between client and server. Now I have some doubts about which is the best method to transfer a file? Option 1 - I use the built in Socket.BeginSendFile (I am using async calls) to transfer a file. Option 2 - I can read the file in chunks in a byte array and use Socket.BeginSend to transfer the files. I have tried bot the methods, both are working satisfactorily. So I want to know which is the best method so that it uses minimum resources on the client side. I am using Socket.BeginReceive on the server end to receive the files.
My other question is how can I keep track of the progress of file upload on the client's end? If I use the option 2 for sending files, i.e. reading them in chunks and calling Socket.BegingSend, I don't get the actual amount of bytes received by the server. I have deployed the server on a computer on a remote server and have seen that my data sending loop on client ends in a zip but the server keeps receiving the data for some time. I understand this is because of my connected speed so how can I know how much data has been received by the server? I can send a bytes received count from the server after each chunk of data has been received, but is there another way?
My third question is how can I implement bandwidth throttling on the client end? I don't want one client with a fat pipe consuming all the bandwidth of the server or even of the client computer.
And my last question is which is the best method to use on the client side? Socket.Send/Socket.SendFile (synch methods) or Socket.BeginSend/Socket.BeginSendFile (asynch methods)? A lot of clients will be connected to the server and they will be uploading files simultaneously. I am using BeginReceive at the server end but I am not sure if I can use Send/SendFile at the client end. Which would be the best option?
I hope someone will be able to help.
-Yash