I'm writing a client server UDP and it works though remaining bytes are represented as boxes which is something I don't want.
import java.io.*; import java.net.*; public class PacketClientSendDemo{ public static void main(String[]args)throws IOException{ DatagramSocket socket = new DatagramSocket(); String tot = "Hello Server"; byte[] data = tot.getBytes(); InetAddress addr = InetAddress.getLocalHost(); DatagramPacket packet = new DatagramPacket(data, data.length, addr,8797); socket.send(packet); packet.setData(new byte[1024]); socket.receive(packet); System.out.println(new String(packet.getData())); } }import java.io.*; import java.net.*; public class PacketServerReceiveDemo{ public static void main(String[] args)throws IOException{ DatagramSocket socket = new DatagramSocket(8797); DatagramPacket packet = new DatagramPacket(new byte[1024],1024); socket.receive(packet); System.out.println(new String(packet.getData())); socket.send(packet); } }