public class Server {
public static void main(String[] args) {
try {
DatagramSocket ds = new DatagramSocket(new InetSocketAddress(8888));
while (true) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
DatagramPacket data = new DatagramPacket(buf, buf.length);
ds.receive(data);
baos.write(data.getData(), 0, data.getLength());
System.out.println(new String(baos.toByteArray()));
buf = baos.toByteArray();
ds.send(new DatagramPacket(buf, buf.length, data.getSocketAddress()));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}