简体   繁体   English

我应该使用HTTP服务器还是FTP服务器进行文件下载? 在这里如何使用P2P协议?

[英]Should I use a HTTP server or a FTP server for file download ? How can I use a P2P protocol here?

In my webapp users can download the files among themselves. 在我的webapp中,用户可以相互下载文件。 If a user A has shared a file F , then user B after connecting to A can download the file F from A . 如果用户A共享了文件F ,则用户B连接到A可以从A下载文件F Till now each user makes a simple HTTP connection like : xxx.xxx.xxx.xxx/FileList with another user. 直到现在,每个用户都与另一个用户建立了一个简单的HTTP连接,例如: xxx.xxx.xxx.xxx/FileList The file resides on the local hard disk of each user. 该文件位于每个用户的本地硬盘上。 So that a user can download a file there were two options in my mind. 为了使用户可以下载文件,我想到了两种选择。

  • As the user shares a file,copy that file into the web-app directory of the server,so that the download link becomes as simple as <a href="./FileToDownload">Click to download</a> . 当用户共享文件时,将该文件复制到服务器的Web应用程序目录中,以使下载链接变得像<a href="./FileToDownload">Click to download</a>一样简单。
  • Run a separate FTP server on each node. 在每个节点上运行单独的FTP服务器。

I don't know which one of these is a better option but the first one seems very simple to me. 我不知道哪个是更好的选择,但是第一个对我来说似乎很简单。 What are the ways each client can share the files,without having to copy the stuff somewhere in the webapp directory. 每个客户端可以通过什么方式共享文件,而不必将内容复制到webapp目录中的某处。 How in this case I can use a P2P protocol ? 在这种情况下,如何使用P2P协议?

NOTE : I am using Tomcat 7. 注意:我正在使用Tomcat 7。

Real P2P is impossible without opening a listening socket on the client machine (that imposes you have to install something on client machine). 如果不在客户端计算机上打开侦听套接字,则真正的P2P是不可能的(这意味着您必须在客户端计算机上安装某些组件)。

If you don't want to STORE the files on the server, I would rather recommend a "connection server", which serves as a gateway between the two users. 如果您不想在服务器上存储文件,则建议使用“连接服务器”,该服务器用作两个用户之间的网关。 User A will upload, user B will download at the same time, all you need is to make the bytebuffer in memory. 用户A将上传,用户B将同时下载,您所需要做的就是在内存中创建字节缓冲区。 The downloaded bytes can be dropped. 可以删除下载的字节。

You can write a small client-side program in any language for updating the available files, and receiving the upload request from the server side (also execute the upload) I would recommend using TCP sockets for upload to the server side, this way you have direct control over the uploaded bytes (streams). 您可以用任何语言编写一个小的客户端程序来更新可用文件,并从服务器端接收上传请求(也执行上传)。我建议使用TCP套接字将其上传到服务器端,这样您就可以直接控制上载的字节(流)。

There are some interesting technical issues here (blocking streams, metadata (filename, length, createdate, ...), data consistency, error handling, etc.) that should be taken into consideration. 这里有一些有趣的技术问题(阻塞流,元数据(文件名,长度,createdate,...),数据一致性,错误处理等)应予以考虑。 Nice task. 做得好

I don't recommend FTP because you cannot control the authentication and authorisation (who can see the files). 我不建议使用FTP,因为您无法控制身份验证和授权(谁可以看到文件)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM