简体   繁体   English

Java套接字和TCP调整

[英]Java sockets and TCP tuning

I try to develop a file transfer application in Java, with an applet as client, and a standalone java app as server (on a dedicated machine hosted in a datacenter). 我尝试开发Java中的文件传输应用程序,与一个applet作为客户端,和一个独立的Java应用程序服务器作为(专用机器上的数据中心托管)。 I use DataOutputStream/DataInputStream to transfers the data on both sides. 我使用DataOutputStream / DataInputStream在两侧传输数据。 When I send big volumes of data, the bandwith is very variable : all is okay first, then the tcp stream is freezed during 40-50 seconds while nothing is transferring, and then it starts again. 当我发送数据的大容量,带宽将是非常变量:全是好的,再而没有被传输的TCP流中40-50秒的冻结,然后重新开始。

When I look at the tcp stream with Ethereal, I see duplicate acks, fast retransmits, and tcp retransmits. 当我看着空灵的TCP流中,我看到的重复ACK,快速重传和TCP重新。 But I don't think that the problem is originating from Java : I have the same problem with FTP transfers in FileZilla. 但是我不认为问题出在Java:FileZilla中的FTP传输也有同样的问题。 But ... when I try to transfer data using netcat (netcat client + netcat server), all is fine, the bandwith is stable, the tcp lost packets seems to be retransmitted immediately without any pause, no matter of the volume transferred. 但是......当我尝试使用netcat(netcat客户端+ netcat服务器)传输数据时,一切都很好,带宽稳定,tcp丢失的数据包似乎立即重传,没有任何暂停,无论传输的音量。

It's like if Java was not as talented as netcat to play with tcp streams ... 就像Java在处理TCP流方面不如netcat那样有才...

I tried to play with Socket.setSendBufferSize(), but I didn't see any difference. 我尝试使用Socket.setSendBufferSize(),但没有发现任何区别。 Any idea ? 任何想法 ?

Thanks ! 谢谢 ! And sorry for my bad english ... 很遗憾我的英语不好...

Mr amischiefr is right ! 阿米施菲尔先生是对的! It's the same problem that on the other thread. 这与另一个线程上的问题相同。 My problem was solved by replacing DataXXXputStream by BufferedXXXputstream. 我的问题通过用BufferedXXXputstream替换DataXXXputStream来解决。 The write(byte[], off, len) methods are the same, and the doc doesn't talk about such different behavior. write(byte [],off,len)方法是相同的,并且文档没有讨论这种不同的行为。 DataOutputStream is buffered, BufferedOutputStream too, but the second one does it much better. DataOutputStream也有缓冲,BufferedOutputStream也有缓冲,但是第二个缓冲要好得多。 Thanks ! 谢谢 !

听起来更像是您的网络陷入了瘫痪,并且您看到TCP窗口(我相信这是正确的术语)基本上限制了带宽。

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

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