Hi people! Python server:

import socket, os s = socket.socket() s.bind(('0.0.0.0', 500)) s.listen(5) while True: c, addr = s.accept() data = c.recv(1024) print(str(data)) 

Java client:

 String data = "Test"; try (Socket socket = new Socket("localhost", 5000)) { try (DataOutputStream os = new DataOutputStream(socket.getOutputStream())) { while(true){ os.write(data.getBytes("utf-8"), 0, data.length()); } } } 

With a very large packet flow, gluing occurs (the server prints "TestTe" or TestTestTest) how to fix it?

  • one
    I know a great joke about UDP, but not the fact that it comes to you. - Sergey Gornostaev
  • 2
    And I also know a joke about TCP. If it does not reach you, I will repeat it again - Andrew Grow
  • @AndrewGrow so how to remove it? - Cus

1 answer 1

UDP uses a simple transfer model, with no implicit handshakes, to ensure reliability, ordering, or data integrity. Thus, UDP provides an unreliable service, and datagrams may come out of order, be duplicated, or disappear altogether without a trace . UDP implies that error checking and correction are either not needed or must be performed in an application.

https://ru.wikipedia.org/wiki/UDP

From this it follows that you have to send a serial number from the client along with each symbol, and on the server add a verification code that the numbers are consecutive without breaks, the code for re-requesting lost packets, the duplicate ignoring code and the ordering code of received data. Or go to the use of TCP, which implements all of this for you.

  • and how to remove the bonding packages? - Cus
  • and server on tcp - Cus