用java发送大文件
如何使用套接字通过网络发送大文件(2-3 GB)?我编写了一个套接字程序,它将文件从服务器发送到客户端。但即使发送 300 MB 也需要很长时间。
How to send large files (2-3 GB) over the network using sockets? I have written a socket program which sends files from the server to client. But it is taking a very long time to send even 300 MB.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
判断网络是否是瓶颈,如果是则在发送前压缩文件。使用
DeflaterOutputStream
在发送方和InflaterInputStream
在接收器中。 (如果文件已经压缩,请不要执行此操作;许多媒体格式都包含压缩。)Determine whether the network is the bottleneck and compress the files before sending if it is. Use
DeflaterOutputStream
in the sender andInflaterInputStream
in the receiver. (Don't do this if the files are already compressed; many media formats include compression.)大文件可能需要很长时间,具体取决于您的互联网连接的上传速度。
假设您有上传速度为 128 Kb 的宽带。 (您的下载速度并不重要)
每秒最多传输 16 KB(千字节)。这意味着 1 MB 应花费超过一分钟,1 GB 应花费超过 16 小时。
Large files can take a long time depending on the upload speed of your Internet connection.
Say you have broadband with an upload speed of 128 Kb. (Your download speed doesn't matter)
This will transfer up to 16 KB (kilo-bytes) per second. This means 1 MB should take over a minute and 1 GB should take over 16 hours.