473,748 Members | 6,037 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# - Best way to transfer files using Sockets

yashg
1 New Member
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.BeginSen dFile (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.BeginSen d 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.BeginRec eive 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.BegingSe nd, 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.BeginSen d/Socket.BeginSen dFile (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 16812
fealves
1 New Member
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 Recognized Expert Moderator Expert
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....especiall y 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 "initializi ng" 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
1143
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: System.IO.IOException "Unable to read data from the transport connection." In this case it writes only 2 or 3 files and then
11
6638
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 transfer data across.On the serve I am using Socket 2 API (recv function to read bytes)and not using ..NET. I use FileStream to open the file on the pocket pc, then associate a BinaryReader object with the stream and call ReadBytes to read all the...
10
3478
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 somewhere that each folder under the "web site" is compiled in separate assembly. I however, did not find that the "web site" creation in vs.net 2005 created any AssemblyInfo.cs file.
2
2497
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. Now when i send a file of 150 kb size the file seems to be corrupted at the receivers end. some part of the file is not received. Is there any restriction of size for sending files across internet using sockets?
38
2999
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 having computer #1 to create two duplicate data files sequentially. (file_1.dat & file_2.dat). Then, Computer #2 tries to open file_2.dat and upon failure it opens file_1.dat.
1
1402
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 can´t find the same in VS 2005 ! greetings aaapaul
10
10624
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 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...
3
3561
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 use networkstream with c# sockets... so how do I do it? also, do I need to worry about serialization/deserialization? any help would be greatly appreciated
4
7584
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 client to use is "XOVER articlenumber-" This return string after string of all the news articles from article number on.... Another newsclient, i wont name names, pulls data down just fine. Using a
0
8830
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9544
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9372
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8243
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4606
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2783
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.