通过互联网传输文件(使用java)
我有一个在服务器和客户端上运行的java(swing)应用程序(或者假设两台不同的
计算机),这两台计算机通过互联网连接,而不是通过LAN或WAN连接。客户端必须
向服务器发送一些数据(大约200 kb) .哪种方法更适合传输数据..我
通过LAN使用TCP,但通过互联网速度很慢..那么我可以使用UDP进行互联网吗?如果是,我不
知道如何将数据分成块并发送&再次在服务器上重新组装数据。
如果提供UDP传输(java中的批量数据)的源代码,我真的很感激。
提前致谢..
I've a java(swing) application running on server and client(or assume two different
computers),These two are connected through Internet not by LAN or WAN..The client has to send
some data (around 200 kb) to the server.Which method is preferable for transferring data..I used
TCP through LAN,but it's working slow through Internet..So can I use UDP for internet ? If yes, I don't
know how to divide my data into chunks and send it & again re-assemble the data at the server.
I am really thankful if source code is provided for UDP transfer(bulk data in java).
thanks in advance..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 TCP,它完全按照您想要的方式执行,并且比您希望自己实现的方式要好得多。如果您的带宽较低,请在后台传输或只是等待 - 您对此无能为力。
读取字节数组中的数据并将它们作为一个整体写入 - 请参阅 DataInputStream.readFully()。在写入结束时刷新输出。
编辑:如果您想一张接一张地发送多张图像,您可以进行视频压缩 - 它的设计目的就是为了高效。
Use TCP, it does exactly what you want in a way which is much better than you can hope to implement on your own. If you have low bandwidth, transfer in the background or just wait - there is nothing you can do with that.
Read your data in byte arrays and write them as a whole - see DataInputStream.readFully(). Flush the output at the end of the writing.
Edit:If you want to send multiple images, one after the other, you can do video compression - it is designed to be efficient just at that.
拉维已经为这个问题苦苦挣扎了好几天。现在UDP有望带来帮助,但是,当然,它不会!
Ravi,我免费给你一些更多的提示(因为你到现在为止收到的 7 个答案中连一个都没有投赞成票,我猜 StackOverflow 中的声誉系统对你来说仍然是个谜):
比二维像素数组,即颜色
值(通常是 int 值)。
BTW,请问你的职业是什么?
Ravi is struggeling for some days now with this problem. Now UDP is expected to bring help, but, of course, it won't!
Ravi, I give you some more hints for free (as you have not upvoted even one of the 7 answers you have received until now, I guess the reputation system in StackOverflow is and remains a mystery to you):
than a 2 dimensional array of pixels, i.e. color
values (usually int values).
BTW, may I ask what your profession is?