Java TCP socket: data transfer is slow

后端 未结 12 1961
误落风尘
误落风尘 2020-12-01 09:50

I set up a server with a ServerSocket, connect to it with a client machine. They\'re directly networked through a switch and the ping time is <1ms.

Now, I try to

12条回答
  •  半阙折子戏
    2020-12-01 10:34

    How are you implementing the receiving end? Please post your receiving code as well.

    Since TCP is a reliable protocol, it will take steps to make sure the client is able to receive all of the data sent by the sender. This means that if your client cannot get the data out of the data receive buffer in time, then the sending side will simply stop sending more data until the client has a chance to read all the bytes in the receiving buffer.

    If your receiving side is reading data one byte at a time, then your sender probably will spend a lot of time waiting for the receiving buffer to clear, hence the long transfer times. I'll suggest changing your receiving code to reading as many bytes as possible in each read operation . See if that will solve your problem.

提交回复
热议问题