mdw.nbio
クラス NonblockingDatagramSocket

java.lang.Object
  |
  +--java.net.DatagramSocket
        |
        +--mdw.nbio.NonblockingDatagramSocket
すべての実装インタフェース:
Selectable
直系の既知のサブクラス:
NonblockingMulticastSocket

public class NonblockingDatagramSocket
extends java.net.DatagramSocket
implements Selectable

A NonblockingDatagramSocket provides non-blocking UDP (datagram) I/O.


インタフェース mdw.nbio.Selectable から継承したフィールド
ACCEPT_READY, CONNECT_READY, READ_READY, SELECT_ERROR, WRITE_READY
 
コンストラクタの概要
NonblockingDatagramSocket()
          Create a NonblockingDatagramSocket bound to any available port.
NonblockingDatagramSocket(int port)
          Create a NonblockingDatagramSocket bound to the given port.
NonblockingDatagramSocket(int port, java.net.InetAddress laddr)
          Create a NonblockingDatagramSocket bound to the given port and the given local address.
 
メソッドの概要
 void close()
          Close this NonblockingDatagramSocket.
 void connect(java.net.InetAddress address, int port)
          Connect this NonblockingDatagramSocket to the given address and port.
 void connect(java.lang.String host, int port)
           
 void disconnect()
           
 java.net.InetAddress getInetAddress()
          Return the remote address to which this socket is bound.
 java.net.InetAddress getLocalAddress()
          Return the local address to which this socket is bound.
 int getLocalPort()
          Return the local port to which this socket is bound.
 int getPort()
          Return the remote port to which this socket is bound.
 int getReceiveBufferSize()
           
 int getSendBufferSize()
           
 int nbReceive(byte[] data, int offset, int length)
          Receive a datagram from this socket.
 int nbReceive(java.net.DatagramPacket p)
          Receive a datagram from this socket.
 int nbSend(byte[] data, int offset, int length)
          Sends a datagram packet from this socket.
 int nbSend(byte[] data, int offset, int length, java.net.InetAddress addr, int port)
          Sends a datagram packet from this socket.
 int nbSend(java.net.DatagramPacket p)
          Sends a datagram packet from this socket.
 void receive(java.net.DatagramPacket p)
          This method is provided for convenience and mimics blocking behavior by invoking the nonblocking nbReceive() operation.
 void send(java.net.DatagramPacket p)
          This method is provided for convenience and mimics blocking behavior by invoking the nonblocking nbSend() operation.
 void setReceiveBufferSize(int size)
           
 void setSendBufferSize(int size)
           
 
クラス java.net.DatagramSocket から継承したメソッド
getSoTimeout, setDatagramSocketImplFactory, setSoTimeout
 
クラス java.lang.Object から継承したメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

コンストラクタの詳細

NonblockingDatagramSocket

public NonblockingDatagramSocket()
                          throws java.io.IOException
Create a NonblockingDatagramSocket bound to any available port.

NonblockingDatagramSocket

public NonblockingDatagramSocket(int port)
                          throws java.io.IOException
Create a NonblockingDatagramSocket bound to the given port.

NonblockingDatagramSocket

public NonblockingDatagramSocket(int port,
                                 java.net.InetAddress laddr)
                          throws java.io.IOException
Create a NonblockingDatagramSocket bound to the given port and the given local address.
メソッドの詳細

close

public void close()
Close this NonblockingDatagramSocket.
オーバーライド:
クラス java.net.DatagramSocket 内の close

connect

public void connect(java.net.InetAddress address,
                    int port)
             throws java.lang.IllegalArgumentException
Connect this NonblockingDatagramSocket to the given address and port. All send() operations with a NULL 'sendTo' address will now send to this address by default. You may call connect() multiple times on a NonblockingDatagramSocket to change the default send address.
オーバーライド:
クラス java.net.DatagramSocket 内の connect

connect

public void connect(java.lang.String host,
                    int port)
             throws java.net.UnknownHostException

disconnect

public void disconnect()
オーバーライド:
クラス java.net.DatagramSocket 内の disconnect

getInetAddress

public java.net.InetAddress getInetAddress()
Return the remote address to which this socket is bound. Should be null if the socket hasn't been connected to anything.
オーバーライド:
クラス java.net.DatagramSocket 内の getInetAddress

getLocalAddress

public java.net.InetAddress getLocalAddress()
Return the local address to which this socket is bound.
オーバーライド:
クラス java.net.DatagramSocket 内の getLocalAddress

getPort

public int getPort()
Return the remote port to which this socket is bound.
オーバーライド:
クラス java.net.DatagramSocket 内の getPort

getLocalPort

public int getLocalPort()
Return the local port to which this socket is bound.
オーバーライド:
クラス java.net.DatagramSocket 内の getLocalPort

nbReceive

public int nbReceive(java.net.DatagramPacket p)
              throws java.io.IOException
Receive a datagram from this socket. When this method returns, the DatagramPacket's buffer is filled with the data received. The datagram packet also contains the sender's IP address, and the port number on the sender's machine. This method does not block if a datagram is not ready to be received. The length field of the datagram packet object contains the length of the received message, or is set to 0 if no packet was received. If the message is longer than the packet's length, the message is truncated.
戻り値:
The size of the received packet, or 0 if no data was received.

nbReceive

public int nbReceive(byte[] data,
                     int offset,
                     int length)
              throws java.io.IOException
Receive a datagram from this socket. When this method returns, the given byte array is filled with the data received starting at the given offset with the given length. If the message is longer than the given length, the message is truncated. This method does not block if a datagram is not ready to be received.
戻り値:
The size of the received packet, or 0 if no data was received.

nbSend

public int nbSend(java.net.DatagramPacket p)
           throws java.io.IOException
Sends a datagram packet from this socket. The DatagramPacket includes information indicating the data to be sent, its length, the IP address of the remote host, and the port number on the remote host. This method does not block; it returns 0 if the packet could not be sent.
戻り値:
The amount of data sent, or 0 if the packet could not be sent immediately.

nbSend

public int nbSend(byte[] data,
                  int offset,
                  int length,
                  java.net.InetAddress addr,
                  int port)
           throws java.io.IOException
Sends a datagram packet from this socket. This method constructs a temporary DatagramPacket from the given data, offset, length, address, and port, and calls nbSend(DatagramPacket p). This method does not block; it returns 0 if the packet could not be sent.
戻り値:
The amount of data sent, or 0 if the packet could not be sent immediately.

nbSend

public int nbSend(byte[] data,
                  int offset,
                  int length)
           throws java.io.IOException
Sends a datagram packet from this socket. This method constructs a temporary DatagramPacket from the given data, offset, and length. This method may only be called on a connected socket; if called on an unconnected socket, an IllegalArgumentException is thrown. This method does not block; it returns 0 if the packet could not be sent.
戻り値:
The amount of data sent, or 0 if the packet could not be sent immediately.

getReceiveBufferSize

public int getReceiveBufferSize()
                         throws java.net.SocketException
オーバーライド:
クラス java.net.DatagramSocket 内の getReceiveBufferSize

getSendBufferSize

public int getSendBufferSize()
                      throws java.net.SocketException
オーバーライド:
クラス java.net.DatagramSocket 内の getSendBufferSize

setReceiveBufferSize

public void setReceiveBufferSize(int size)
                          throws java.net.SocketException
オーバーライド:
クラス java.net.DatagramSocket 内の setReceiveBufferSize

setSendBufferSize

public void setSendBufferSize(int size)
                       throws java.net.SocketException
オーバーライド:
クラス java.net.DatagramSocket 内の setSendBufferSize

send

public void send(java.net.DatagramPacket p)
          throws java.io.IOException
This method is provided for convenience and mimics blocking behavior by invoking the nonblocking nbSend() operation. If the packet could not be immediately sent it is simply dropped (because this is a UDP socket this behavior is consistent with the lack of reliability in UDP).

Use of this method is not recommended and is provided only for compatibility with java.net.DatagramSocket.

オーバーライド:
クラス java.net.DatagramSocket 内の send

receive

public void receive(java.net.DatagramPacket p)
             throws java.io.IOException
This method is provided for convenience and mimics blocking behavior by invoking the nonblocking nbReceive() operation. If no packet could be immediately received it returns immediately with a received packet length of 0.

Use of this method is not recommended and is provided only for compatibility with java.net.DatagramSocket.

オーバーライド:
クラス java.net.DatagramSocket 内の receive