UDP packet is not overwritten when it is sent

Hello fellas,
I am sending udp packet from my phone (android app) to my esp32 (arduino code) which is then displayed to my PC using serial.
I have managed to get some packets sent to the esp32 and displayed on PC but it looks like that the packet size is considered to the largest packet.
example:
I send JSK ==> I receive JSK
I send MOB ==> I receive MOB
if I then send JSMB ==> I receive JSMB
now if i send back JSK ==> I receive JSKB
Why is it behaving like that?
here is the receiving code:

void loop() 
{
    if(connected)
  { 
     electrical_values();
    int packetSize = udp.parsePacket();
    if (packetSize) {
    udp.read(packetBuffer, packetSize);
     Serial.println(packetBuffer);
    }
    //Send a packet
    udp.beginPacket(udpAddress,udpPort);
     String str(packetBuffer);
     Packets = /*Packets + "@" +*/ packetBuffer;
     udp.print(packetBuffer);
     udp.endPacket();      
  }}}

The buffer contains "JSMB" and when you receive "JSK" into that buffer, it will be "JSKB" ("JSM" is replaced with "JSK" - the last "B" remains). You need to check how much data is transmitted per packet, and only use that much data from the buffer, or you need to clear the buffer using "memset" before receiving.

it is now fine that I have used this

for(int i=0;i<UDP_TX_PACKET_MAX_SIZE;i++) packetBuffer[i] = 0;

Much faster to "memset(packetBuffer, 0, sizeof(packetBuffer))" before reception, or even better "packetBuffer[packetSize]=0" after reception (please check buffer size first, though).