I just want to know which is the best way to transfer files between clients and server. My server is accessed from client through internet. I found some results after googled as using tcp/udp/ftp... So , i just want to know which one is best and why ? . My file size could be around 100MB each , and also i want to setup it for multiple client ...

Recommended Answers

All 9 Replies

I think FTP is the best. It has been successful for years and has a lot of benefits.
You can handle FTP at a low-level or high-level and all modern languages support it.
The classes in .NET are easy to use and can communicate with a number of servers.
A number of libraries are also available for secure FTP.

I believe a multithreaded TCP Server which supports asynchronous communications may be a good solution

I would use the method AcceptTcpClient of the System.Net.Sockets.TcpListener class to accept connections. Every time a new client connects, start a new thread to handle the connection.

A single TCP endpoint (IP address and port) can serve multiple connections. All you need to do is create a worker object on the server that will handle each connection on a separate thread. The TcpListener.AcceptTcpClient method returns a TcpClient when a connection is established. This should be passed off to a threaded worker object so that the worker can communicate with the remote client.

To exchange network data asynchronously, you can use the NetworkStream class, which includes support for asynchronous communication through the BeginRead and BeginWrite methods. Using these methods, you can send or receive a block of data on one of the threads provided by the thread pool, without blocking your code.

One advantage of this approach when sending files is that the entire content of the file does not have to be held in memory at once. Instead, it is retrieved just before a new block is sent. Another advantage is that the server can abort the transfer operation easily at any time.

Recapping, this approach is most appropriate for a production environment where there are a lot of clients connecting simultaneously to the server. If your target environment is a home network with a few clients, then this approach might be overkill

Thanks for that post ... I go with this ...

I just want to setup a server (file distribution) and multiple clients . There may be simultaneous send and receive operations at server side . So, what are all the facts i could consider ... (Visual studio.net , framework 3.5)...

BobS0327 have you enough to consider, right?
...just do it.
You may find your design will change after you get started, anyway.

I just want to setup a server (file distribution) and multiple clients . There may be simultaneous send and receive operations at server side . So, what are all the facts i could consider ... (Visual studio.net , framework 3.5)...

You may want to start your project on the server side.

The server would start a thread-pool thread listening for new connections using the TcpListener.BeginAcceptTcpClient
method and specifying a callback method to handle the new connections. Every time a client connects to the server,
the callback method obtains the new TcpClient object and passes it to a new threaded ClientHandler object to handle client

The ClientHandler object waits for the client to request data and then sends a large amount of data
(read from a file) to the client. This data is sent asynchronously, which means ClientHandler could
continue to perform other tasks. In this example, it simply monitors the network stream for messages
sent from the client. The client reads only a third of the data before sending a disconnect message to the
server, which terminates the remainder of the file transfer and drops the client connection.

The above will give you something to work with if you feel this is the best approach to your problem. Obviously, there is a lot more to be done before your project is complete. But at this point, I really don't want to write a post the size of Tolstoy's War and Peace to explain all the details.

Sorry for the typo in my last post.
That second word was "gave" not "have".

If you are sending the same file to many different clients, it may be wise to keep the entire file(s) in memory to avoid harddrive bottlenecking. FTP and TCP are pretty viable options. But for speed and less server bandwidth consumption you could also look into the bittorrent protocol.


Thanks for that detailed explain .I think i have a clear concept after reading this. Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.