Code example for DatagramChannel

Methods: receive

0
	public void readInboundData (ByteBuffer dst) {
		returnAddress = null;
		try { 
			// If there is no datagram available (we're nonblocking after all), 
			// then channel.receive returns null. 
			returnAddress = channel.receive(dst);
		} catch (IOException e) {
			// probably a no-op. The caller will see the empty (or even partial) buffer 
			// and presumably do the right thing. 
		} 
	} 
	 
	public boolean writeOutboundData() { 
		while (!outboundQ.isEmpty()) {
			Packet p = outboundQ.getFirst();
			int written = 0;
			try { 
				// With a datagram socket, it's ok to send an empty buffer. 
				written = channel.send(p.bb, p.recipient);
			} 
			catch (IOException e) {