开发者

Filetransfer app in VB.Net UDP vs TCP and

开发者 https://www.devze.com 2023-02-04 15:13 出处:网络
I\'m developing a filetransfer app in VB.Net The sizes of the files vary开发者_如何学JAVA, but can get up to 10+ GB.

I'm developing a filetransfer app in VB.Net

The sizes of the files vary开发者_如何学JAVA, but can get up to 10+ GB.

I already create a chat app as a test.

On the clientside I run this code to connect to the server.

Dim clientSocket As New System.Net.Sockets.TcpClient()
Dim serverStream As NetworkStream
clientSocket.Connect("127.0.0.1", 80)

Can I also use this to transfer files?

I want the app to work through a firewall and stuff.

So I think I need the outgoing data on the client to go through port 80. On the server I want to be able to receive the data on another port (E.g. 8888). Is this possible?

And final question is. What protocol should I use for this purpose TCP or UDP.

Sorry for the three-in-one question :)

Thanks for helping me out.


Transfer Files: Yes you can very well use a reliable network stream to transfer files. Well at least the data of those files. You have to do the file system management (creating the destination file in the right folder, etc.) yourself.

TCP/UDP: As you need reliability and flow control to transfer big chunks of data over the internet, you might want to go for TCP. Also the other features of TCP like in-order delivery and error detection won't hurt. You would probably end up implementing all those yourself if using UDP, wasting a lot of your time.

Firewall: There shouldn't be a problem with firewalls on the client side of your application, unless they are really very strict and only allow outgoing HTTP connections. But the server port has to be accessible from the internet, that is you want your server side network configured such that incoming connection requests to your public IP and your chosen port are forwarded to the chosen port on your server. Look up "port forwarding" or "port NAT" for more information. Bypassing firewalls and NATs on both sides is really much more difficult if not impossible. Don't try.


In order to transfer extremely large files like you have, you are going to need to break them up into small chunks. This will help you set up an application that can resume after a network error. It is for this reason, as well as many others, that you also want to choose TCP for your transport protocol. UDP might be faster than TCP, but it doesn't have the error detection and correction you are going to need in order to have a safe transfer of data.

Here is a C# article on how to transfer large files from both the client and server perspective. If this is what you are looking for, you will just need to translate the code to VB.NET (which a translator can do automatically for your).

http://codetechnic.blogspot.com/2009/02/sending-large-files-over-tcpip.html

Basically, the code converts the file over to a byte array and then sends it across the network/Internet. Since you can choose the port you use, you won't have an issue with firewalls when you host this. On the client end, when the client initializes the connection, it will be an outbound initialization so it will go out of the network without any issue.


I assume you are on Windows, so just use BITS

There is a nice .net wrapper available sharpbits

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号