mdw.nbio
クラス NonblockingSocket

java.lang.Object
  |
  +--java.net.Socket
        |
        +--mdw.nbio.NonblockingSocket
すべての実装インタフェース:
Selectable

public class NonblockingSocket
extends java.net.Socket
implements Selectable

A NonblockingSocket is a socket which exports nonblocking input/output streams. It is otherwise idential to a standard socket. Socket connection can be either blocking or nonblocking. Use of the standard constructors causes the current thread to block until the connection is established. Otherwise, there are 3 ways to check if the connection has been established: (1) Call finishConnection, (2) Call connectDone, or (3) Create a SelectSet and select on the event Selectable.CONNECT_READY, then call connectDone.

関連項目:
SelectSet

インタフェース mdw.nbio.Selectable から継承したフィールド
ACCEPT_READY, CONNECT_READY, READ_READY, SELECT_ERROR, WRITE_READY
 
コンストラクタの概要
NonblockingSocket(java.net.InetAddress address, int port)
          Create a NonblockingSocket connection to the given host and port number.
NonblockingSocket(java.net.InetAddress address, int port, boolean block)
          Create a NonblockingSocket connection to the given host and port number.
NonblockingSocket(java.lang.String host, int port)
          Create a NonblockingSocket connection to the given host and port number.
NonblockingSocket(java.lang.String host, int port, boolean block)
          Create a NonblockingSocket connection to the given host and port number.
 
メソッドの概要
 void close()
          Closes the socket.
 boolean connectDone()
          Indicate whether the connection on this socket has been established.
 boolean finishConnect(int timeout)
          Block until the connection on this socket has been established.
 java.net.InetAddress getInetAddress()
          Return the remote address to which this socket is bound.
 java.io.InputStream getInputStream()
          Return an InputStream from which data on this socket can be read.
 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.
 java.io.OutputStream getOutputStream()
          Return an OutputStream to which data on this socket can be written.
 int getPort()
          Return the remote port to which this socket is bound.
 int getSoLinger()
          Currently unimplemented.
 int getSoTimeout()
          Currently unimplemented.
 boolean getTcpNoDelay()
          Currently unimplemented.
 void setSoLinger(boolean on, int val)
          Currently unimplemented.
 void setSoTimeout(int timeout)
          Currently unimplemented.
 void setTcpNoDelay(boolean on)
          Currently unimplemented.
 java.lang.String toString()
           
 
クラス java.net.Socket から継承したメソッド
getKeepAlive, getReceiveBufferSize, getSendBufferSize, setKeepAlive, setReceiveBufferSize, setSendBufferSize, setSocketImplFactory, shutdownInput, shutdownOutput
 
クラス java.lang.Object から継承したメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

コンストラクタの詳細

NonblockingSocket

public NonblockingSocket(java.lang.String host,
                         int port)
                  throws java.net.UnknownHostException,
                         java.io.IOException
Create a NonblockingSocket connection to the given host and port number. This will block until the connection is established.

NonblockingSocket

public NonblockingSocket(java.lang.String host,
                         int port,
                         boolean block)
                  throws java.net.UnknownHostException,
                         java.io.IOException
Create a NonblockingSocket connection to the given host and port number. If 'block' is true, block until the connection is done.

NonblockingSocket

public NonblockingSocket(java.net.InetAddress address,
                         int port)
                  throws java.net.UnknownHostException,
                         java.io.IOException
Create a NonblockingSocket connection to the given host and port number. This will block until the connection is established.

NonblockingSocket

public NonblockingSocket(java.net.InetAddress address,
                         int port,
                         boolean block)
                  throws java.io.IOException
Create a NonblockingSocket connection to the given host and port number. If 'block' is true, block until the connection is done.
メソッドの詳細

finishConnect

public boolean finishConnect(int timeout)
                      throws java.net.SocketException
Block until the connection on this socket has been established. 'timeout' specifies the maximum number of milliseconds to block. A timeout of zero indicates no blocking (in which case this call is equivalent to connectDone). A timeout of -1 causes this call to block indefinitely until the connection is established.
戻り値:
true is the connection was established, false if still pending.

connectDone

public boolean connectDone()
                    throws java.net.SocketException
Indicate whether the connection on this socket has been established. Throws an exception if an error occurred trying to connect.

getInetAddress

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

getLocalAddress

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

getPort

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

getLocalPort

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

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Return an InputStream from which data on this socket can be read. The returned InputStream is actually a NonblockingInputStream and provides nonblocking semantics.
オーバーライド:
クラス java.net.Socket 内の getInputStream

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Return an OutputStream to which data on this socket can be written. The returned OutputStream is actually a NonblockingOutputStream and provides nonblocking semantics.
オーバーライド:
クラス java.net.Socket 内の getOutputStream

setTcpNoDelay

public void setTcpNoDelay(boolean on)
                   throws java.net.SocketException
Currently unimplemented.
オーバーライド:
クラス java.net.Socket 内の setTcpNoDelay

getTcpNoDelay

public boolean getTcpNoDelay()
                      throws java.net.SocketException
Currently unimplemented.
オーバーライド:
クラス java.net.Socket 内の getTcpNoDelay

setSoLinger

public void setSoLinger(boolean on,
                        int val)
                 throws java.net.SocketException
Currently unimplemented.
オーバーライド:
クラス java.net.Socket 内の setSoLinger

getSoLinger

public int getSoLinger()
                throws java.net.SocketException
Currently unimplemented.
オーバーライド:
クラス java.net.Socket 内の getSoLinger

setSoTimeout

public void setSoTimeout(int timeout)
                  throws java.net.SocketException
Currently unimplemented.
オーバーライド:
クラス java.net.Socket 内の setSoTimeout

getSoTimeout

public int getSoTimeout()
                 throws java.net.SocketException
Currently unimplemented.
オーバーライド:
クラス java.net.Socket 内の getSoTimeout

close

public void close()
           throws java.io.IOException
Closes the socket.
オーバーライド:
クラス java.net.Socket 内の close

toString

public java.lang.String toString()
オーバーライド:
クラス java.net.Socket 内の toString