简体   繁体   中英

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). I use DataOutputStream/DataInputStream to transfers the data on both sides. 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.

When I look at the tcp stream with Ethereal, I see duplicate acks, fast retransmits, and tcp retransmits. But I don't think that the problem is originating from Java : I have the same problem with FTP transfers in FileZilla. 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.

It's like if Java was not as talented as netcat to play with tcp streams ...

I tried to play with Socket.setSendBufferSize(), but I didn't see any difference. 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. The write(byte[], off, len) methods are the same, and the doc doesn't talk about such different behavior. DataOutputStream is buffered, BufferedOutputStream too, but the second one does it much better. Thanks !

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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