473,405 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

C# - Best way to transfer files using Sockets

yashg
1
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
Sep 19 '07 #1
2 16767
I would like to discuss the subject with you. Please let me know if you have already found the answers you are looking for.

Feel free to contact me at <email removed>
Jul 28 '09 #2
Frinavale
9,735 Expert Mod 8TB
Hi fealves,

I'm working on something similar to what the OP has asked about. I'm not sure how this question was over looked (3 years ago).

Files are sent in chunks so there's no need to break it up....especially since the OP is using asynchronous sockets to send the data.

On the file receiving end, there's no way to tell how big the file is that's being sent. Sending the file size information as part of the file being sent by pre-pending the of the file to the byte array seems to be the best way to go.

It's not easy to keep track of if you send down a separate "initializing" package first.

See my current thread on the same topic. I'm still having problems but there's a discussion going on there talking about the issues touched on here and it might give you a good idea about what types of things you're going to run into when using asynchronous sockets.

If your question differs from mine, feel free to start your own thread :)
Jul 29 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Ali Gohar | last post by:
hi, I want to transfer image files from one computer to another through Sockets in the form of bytes. But after sending 10 to 12 Files there occur an Exception as Follows: ...
11
by: Abhishek | last post by:
I have a problem transfering files using sockets from pocket pc(.net compact c#) to desktop(not using .net just mfc and sockets 2 API). The socket communication is not a issue and I am able to...
10
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read...
2
by: Pramod | last post by:
Hi all, I have created a chat application, and one of it's functionality to send files to the connected user. I read the contents of the files into a Byte array and send that through sockets....
38
by: Tom | last post by:
I need my data generating C program on computer #1 to export small amounts of data (one - 40 byte data structure) periodically (once per minute) to a C program on computer #2. I am considering...
1
by: aaapaul | last post by:
What is the best way to transfer the necessary files of a website to the webserver. In VS2003 there was a possibility to say Project copy -only files, which are necessary for running ! I...
10
by: David | last post by:
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...
3
by: prognoob | last post by:
I need help coding a file transfer in C#. It would be over TCP/IP using sockets... most of the solutions i have come across, they use networkstream and i have read online that there is no need to...
4
by: Andrew Jackson | last post by:
I am writing a newsgroup client. I have the protocol figured out. But I get slow transfer speeds off any of the network objects read the data from For example one of the commands for a news...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.