VB.Net UDP 与 TCP 中的文件传输应用程序和
我正在 VB.Net 中开发一个文件传输应用程序。
文件的大小各不相同,但最多可达 10+ GB。
我已经创建了一个聊天应用程序作为测试。
在客户端,我运行此代码来连接到服务器。
Dim clientSocket As New System.Net.Sockets.TcpClient()
Dim serverStream As NetworkStream
clientSocket.Connect("127.0.0.1", 80)
我也可以用它来传输文件吗?
我希望该应用程序能够穿过防火墙之类的东西。
所以我认为我需要客户端上的传出数据通过端口 80。在服务器上我希望能够在另一个端口(例如 8888)上接收数据。这可能吗?
最后一个问题是。我应该使用什么协议来实现此目的 TCP 或 UDP。
抱歉问了这个三合一的问题:)
谢谢你帮助我。
I'm developing a filetransfer app in VB.Net
The sizes of the files vary, 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
传输文件:是的,您可以很好地使用可靠的网络流来传输文件。至少这些文件的数据。您必须自己进行文件系统管理(在正确的文件夹中创建目标文件等)。
TCP/UDP:由于您需要可靠性和流量控制来通过互联网传输大块数据,因此您可能需要选择 TCP。 TCP 的其他功能(如按顺序传送和错误检测)也不会受到影响。如果使用 UDP,您可能最终会自己实现所有这些,浪费大量时间。
防火墙:应用程序客户端的防火墙不应该有问题,除非它们确实非常严格并且只允许传出 HTTP 连接。但是服务器端口必须可以从互联网访问,也就是说,您希望配置服务器端网络,以便将对您的公共 IP 和您选择的端口的传入连接请求转发到服务器上的所选端口。查找“端口转发”或“端口 NAT”以获取更多信息。绕过双方的防火墙和 NAT 即使不是不可能,也确实要困难得多。不要尝试。
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.
为了传输像您这样的超大文件,您需要将它们分成小块。这将帮助您设置一个可以在网络错误后恢复的应用程序。正是由于这个原因以及许多其他原因,您还希望选择 TCP 作为传输协议。 UDP 可能比 TCP 更快,但它不具备安全传输数据所需的错误检测和纠正功能。
这是一篇关于如何从客户端和服务器角度传输大文件的 C# 文章。如果这就是您正在寻找的内容,您只需将代码翻译为 VB.NET(翻译器可以自动为您完成此操作)。
http://codetechnic.blogspot.com/2009/02 /sending-large-files-over-tcpip.html
基本上,代码将文件转换为字节数组,然后通过网络/Internet 发送它。由于您可以选择使用的端口,因此在托管时不会遇到防火墙问题。在客户端,当客户端初始化连接时,这将是出站初始化,因此它将毫无问题地走出网络。
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.
我假设您使用的是 Windows,因此只需使用 BITS
有一个不错的 .net 包装器可用 sharpbits
I assume you are on Windows, so just use BITS
There is a nice .net wrapper available sharpbits