/** * This always returns false since the simple DatagramSocket usage * cannot be run in a non-blocking way. */ public boolean available() { // It would take a separate thread or an NIO Selector based implementation to get this // to work. If a polling strategy is never employed by callers then it doesn't // seem worth it to implement all of that just for this method. checkClosed(); return false; }
public void close() { checkClosed(); DatagramSocket temp = sock; sock = null; connected.set(false); temp.close(); }
public void write( ByteBuffer data ) { checkClosed(); try { DatagramPacket p = new DatagramPacket( data.array(), data.position(), data.remaining(), remoteAddress ); sock.send(p); } catch( IOException e ) { throw new ConnectorException( "Error writing to connection:" + remoteAddress, e ); } } }
public ByteBuffer read() { checkClosed(); try { DatagramPacket packet = new DatagramPacket( buffer, buffer.length ); sock.receive(packet); // Wrap it in a ByteBuffer for the caller return ByteBuffer.wrap( buffer, 0, packet.getLength() ); } catch( IOException e ) { if( !connected.get() ) { // Nothing to see here... just move along return null; } throw new ConnectorException( "Error reading from connection to:" + remoteAddress, e ); } }
/** * This always returns false since the simple DatagramSocket usage * cannot be run in a non-blocking way. */ public boolean available() { // It would take a separate thread or an NIO Selector based implementation to get this // to work. If a polling strategy is never employed by callers then it doesn't // seem worth it to implement all of that just for this method. checkClosed(); return false; }
/** * This always returns false since the simple DatagramSocket usage * cannot be run in a non-blocking way. */ public boolean available() { // It would take a separate thread or an NIO Selector based implementation to get this // to work. If a polling strategy is never employed by callers then it doesn't // seem worth it to implement all of that just for this method. checkClosed(); return false; }
public void close() { checkClosed(); DatagramSocket temp = sock; sock = null; connected.set(false); temp.close(); }
public void close() { checkClosed(); DatagramSocket temp = sock; sock = null; connected.set(false); temp.close(); }
public void write( ByteBuffer data ) { checkClosed(); try { DatagramPacket p = new DatagramPacket( data.array(), data.position(), data.remaining(), remoteAddress ); sock.send(p); } catch( IOException e ) { throw new ConnectorException( "Error writing to connection:" + remoteAddress, e ); } } }
public void write( ByteBuffer data ) { checkClosed(); try { DatagramPacket p = new DatagramPacket( data.array(), data.position(), data.remaining(), remoteAddress ); sock.send(p); } catch( IOException e ) { throw new ConnectorException( "Error writing to connection:" + remoteAddress, e ); } } }
public ByteBuffer read() { checkClosed(); try { DatagramPacket packet = new DatagramPacket( buffer, buffer.length ); sock.receive(packet); // Wrap it in a ByteBuffer for the caller return ByteBuffer.wrap( buffer, 0, packet.getLength() ); } catch( IOException e ) { if( !connected.get() ) { // Nothing to see here... just move along return null; } throw new ConnectorException( "Error reading from connection to:" + remoteAddress, e ); } }
public ByteBuffer read() { checkClosed(); try { DatagramPacket packet = new DatagramPacket( buffer, buffer.length ); sock.receive(packet); // Wrap it in a ByteBuffer for the caller return ByteBuffer.wrap( buffer, 0, packet.getLength() ); } catch( IOException e ) { if( !connected.get() ) { // Nothing to see here... just move along return null; } throw new ConnectorException( "Error reading from connection to:" + remoteAddress, e ); } }