Guys. Hey. Faced such a problem, if you send packets from the engine to the server with a frequency of more than 20 times / sec, they begin to merge, in particular, the end of the old is added to the beginning of the new one. For example, two messages are sent that consider the same action: login lines and the same one. But the server sees as action:loginaction:login . This is the situation with TCP. Is there any way to solve this problem?

 if (inputStream.available() > 0) { System.out.println("Have messege"); byte[] bytes = new byte[1024]; int length; length = inputStream.read(bytes); String result =new String(bytes, 0, length); System.out.println(result); } 

I think you understand that transferring data 10 times per second is not very.

  • one
    Add a minimal reproducible example to the question - Mikhail Vaysman
  • 2
    tcp is so arranged. You need to independently determine the boundary between the packages. In the simplest case, you can simply end the package with a line break and read using BufferedReader.readLine() . - zRrr
  • 2
    For some reason you assume that what is sent by one write call will be read by one call to read . It has never been like this. TCP - streaming thing. The boundaries between messages are your responsibility, not TCP protocol. If you want the protocol to follow the message boundaries for you, you need something high-level, like SOAP. - VladD

0