UDP Packet content changes while transmitting

前端 未结 2 1063
甜味超标
甜味超标 2021-01-27 15:04

I\'m programming an Server-Client Software, where the client connects to the server with an port request, the server opens a new port and sends back the new port number. Then th

相关标签:
2条回答
  • 2021-01-27 15:29
    inD = in.getData();
    

    This merely reasserts the same value. Remove.

    message = new String(inD,0,inD.length);
    

    Wrong. You're ignoring the actual length of the received datagram. Change to:

    message = new String(in.getData(), in.getOffset(), in.getLength());
    
    0 讨论(0)
  • 2021-01-27 15:51

    You are sending a string of one size, yet on the other side you are reading the string of 1024 bytes - which you never sent. This will not do. You should either serialize string using serialize() method, or, if you want to send raw string bytes, send string length as a separate part of the message.

    0 讨论(0)
提交回复
热议问题