For example,

try {
  byte buffer = new byte[65536]; 
  DatagramPacket incoming = new DatagramPacket(buffer, buffer.length);
  DatagramSocket ds = new DatagramSocket(2134);
  ds.receive(incoming);
  byte[] data = incoming.getData();
  String s = new String(data, 0, data.getLength());
  System.out.println("Port" + incoming.getPort() + " on " 
   + incoming.getAddress() + " sent this message:");
  System.out.println(s);
}
catch (IOException ex) {
  System.err.println(ex);
}

Previous | Next | Top | Cafe con Leche

Copyright 2003 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified September 6, 2000