Java UDP Truncated Data recieved

I was doing a simple UDP client and server application in java.

I send "DATA" from client to server. Server is supposed to send a string which is 23 characters long to client.

Here is the code for server :

try

{

String text;

int server_port = 3333;

byte[] message = new byte[1500];

DatagramPacket p = new DatagramPacket(message, message.length);

DatagramSocket s = new DatagramSocket(server_port);

s.receive(p);

text = new String(message);

System.out.println(text);

if(text.contains("DATA"))

{

InetAddress IPAddress = p.getAddress();

int port = p.getPort();

String messageStr="1:0:0:0:1:0:1:0:1:0:1:0";

int msg_length=messageStr.length();

message = messageStr.getBytes();

System.out.println(messageStr + " " + message.length);

p = new DatagramPacket(message, msg_length, IPAddress, port);

s.send(p);

}

}

catch(Exception ex)

{

System.out.println(ex.toString());

}

And the client :

try {

String messageStr=message;

int server_port = port;

DatagramSocket s...

Read More »

By: StackOverFlow - 7 days ago

Related Posts