Package java.nio.channels

Examples of java.nio.channels.DatagramChannel.receive()


  public InetSocketAddress readFromAddress () throws IOException {
    DatagramChannel datagramChannel = this.datagramChannel;
    if (datagramChannel == null) throw new SocketException("Connection is closed.");
    lastCommunicationTime = System.currentTimeMillis();
    return (InetSocketAddress)datagramChannel.receive(readBuffer);
  }

  public Object readObject (Connection connection) {
    readBuffer.flip();
    try {
View Full Code Here


                    if (bytes < 1) {
                        System.err.println("write fail :/ " + bytes);
                    } else {
                        buff.position(0);
                        buff.limit(buff.capacity());
                        SocketAddress addy = channel.receive(buff);
                        buff.flip();
                        CoapMessage response = decoder.decode(buff, null);
                        if (response.getId() != id) {
                            System.err.println("gni?");
                        }
View Full Code Here

        boolean failure = true;
        SocketAddress remoteAddress = null;
        try {
            // Receive from the channel in a non blocking mode. We have already been notified that
            // the channel is ready to receive.
            remoteAddress = nioChannel.receive(byteBuffer);
            failure = false;
        } catch (ClosedChannelException e) {
            // Can happen, and does not need a user attention.
        } catch (Throwable t) {
            fireExceptionCaught(channel, t);
View Full Code Here

                //do we have at least one package?
                if ( reader.hasPackage() ) break;
            }
        } else if (channel instanceof DatagramChannel) {
            DatagramChannel dchannel = (DatagramChannel)channel;
            saddr = dchannel.receive(buffer);
            buffer.flip();      // make buffer readable
            if ( buffer.hasArray() )
                reader.append(buffer.array(),0,buffer.limit()-buffer.position(),false);
            else
                reader.append(buffer,buffer.limit()-buffer.position(),false);
View Full Code Here

                //do we have at least one package?
                if ( reader.hasPackage() ) break;
            }
        } else if (channel instanceof DatagramChannel) {
            DatagramChannel dchannel = (DatagramChannel)channel;
            saddr = dchannel.receive(buffer);
            buffer.flip();      // make buffer readable
            if ( buffer.hasArray() )
                reader.append(buffer.array(),0,buffer.limit()-buffer.position(),false);
            else
                reader.append(buffer,buffer.limit()-buffer.position(),false);
View Full Code Here

              return;
            }
            if (key.isReadable()) {
              ByteBuffer readBuffer = byteBufferAllocator.allocate();
              try {
                InetSocketAddress from = (InetSocketAddress) channel.receive(readBuffer);
                if (from == null) {
                  try {
                    channel.close();
                  } catch (IOException ee) {
                  }
View Full Code Here

        boolean failure = true;
        SocketAddress remoteAddress = null;
        try {
            // Receive from the channel in a non blocking mode. We have already been notified that
            // the channel is ready to receive.
            remoteAddress = nioChannel.receive(byteBuffer);
            failure = false;
        } catch (ClosedChannelException e) {
            // Can happen, and does not need a user attention.
        } catch (Throwable t) {
            fireExceptionCaught(channel, t);
View Full Code Here

                //do we have at least one package?
                if ( reader.hasPackage() ) break;
            }
        } else if (channel instanceof DatagramChannel) {
            DatagramChannel dchannel = (DatagramChannel)channel;
            saddr = dchannel.receive(buffer);
            buffer.flip();      // make buffer readable
            if ( buffer.hasArray() )
                reader.append(buffer.array(),0,buffer.limit()-buffer.position(),false);
            else
                reader.append(buffer,buffer.limit()-buffer.position(),false);
View Full Code Here

                //do we have at least one package?
                if ( reader.hasPackage() ) break;
            }
        } else if (channel instanceof DatagramChannel) {
            DatagramChannel dchannel = (DatagramChannel)channel;
            saddr = dchannel.receive(buffer);
            buffer.flip();      // make buffer readable
            if ( buffer.hasArray() )
                reader.append(buffer.array(),0,buffer.limit()-buffer.position(),false);
            else
                reader.append(buffer,buffer.limit()-buffer.position(),false);
View Full Code Here

    private IRubyObject doReceive(Ruby runtime, int length, ReceiveTuple tuple) throws IOException {
        DatagramChannel channel = (DatagramChannel)getChannel();

        ByteBuffer buf = ByteBuffer.allocate(length);

        InetSocketAddress sender = (InetSocketAddress)channel.receive(buf);

        if (sender == null) {
            // noblocking receive
            if (runtime.is1_9()) {
                throw runtime.newErrnoEAGAINReadableError("recvfrom(2) would block");
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.