com.mindbright.nio
public class NetworkConnection extends java.lang.Object
| Constructor and Description | 
|---|
NetworkConnection(java.nio.channels.SocketChannel channel)
Creates a new NetworkConnection based on the provided SocketChannel. 
 | 
NetworkConnection(Switchboard s,
                 java.nio.channels.SocketChannel channel)  | 
| Modifier and Type | Method and Description | 
|---|---|
void | 
close()
Close the connection. 
 | 
java.nio.channels.SocketChannel | 
getChannel()
Get the underlying SocketChannel 
 | 
java.net.InetAddress | 
getInetAddress()
Returns the address to which the socket is connected. 
 | 
NonBlockingInput | 
getInput()
Get the input stream from which one can read data which arrives
 on this socket. 
 | 
java.net.InetAddress | 
getLocalAddress()
Gets the local address to which the socket is bound. 
 | 
int | 
getLocalPort()
Returns the local port to which this socket is bound. 
 | 
NonBlockingOutput | 
getOutput()
Get the output stream to which one can write data to the remote
 end of this socket. 
 | 
int | 
getPort()
Returns the remote port to which this socket is connected. 
 | 
java.net.Socket | 
getSocket()
Get the underlying socket. 
 | 
int | 
getSoTimeout()
Returns setting for SO_TIMEOUT. 
 | 
Switchboard | 
getSwitchboard()
Returns the switchboard implementation which regulates this
 NetworkConnection instance. 
 | 
static NetworkConnection | 
open(java.net.InetAddress address,
    int port)
Creates a network connection to the specified host and port. 
 | 
static NetworkConnection | 
open(java.net.InetAddress address,
    int port,
    boolean block)
Creates a network connection to the specified address and port. 
 | 
static NetworkConnection | 
open(java.lang.String host,
    int port)
Creates a network connection to the specified host and port. 
 | 
static NetworkConnection | 
open(java.lang.String host,
    int port,
    boolean block)
Creates a network connection to the specified host and port. 
 | 
static NetworkConnection | 
open(Switchboard s,
    java.net.InetAddress address,
    int port,
    boolean block)
Creates a network connection to the specified switchboard,
 address and port. 
 | 
void | 
setSoTimeout(int timeout)
Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. 
 | 
void | 
setTcpNoDelay(boolean delay)
Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm). 
 | 
void | 
shutdownOutput()
Disables the output stream for this socket. 
 | 
java.lang.String | 
toString()  | 
public NetworkConnection(java.nio.channels.SocketChannel channel)
                  throws java.io.IOException
java.io.IOExceptionpublic NetworkConnection(Switchboard s, java.nio.channels.SocketChannel channel) throws java.io.IOException
java.io.IOExceptionpublic static NetworkConnection open(java.lang.String host, int port) throws java.io.IOException
Switchboard.notifyWhenConnected
 method.host - the host nameport - the port to connect tojava.io.IOExceptionSwitchboardpublic static NetworkConnection open(java.lang.String host, int port, boolean block) throws java.io.IOException
block> is false then the call will return directly
 and the progress can be monitored via the
 Switchboard.notifyWhenConnected
 method.host - the host nameport - the port to connect toblock - true if the call should block until the connection
              is establishedjava.io.IOExceptionSwitchboardpublic static NetworkConnection open(java.net.InetAddress address, int port) throws java.io.IOException
Switchboard.notifyWhenConnected
 method.address - IP-address of remote serverport - the port to connect tojava.io.IOExceptionSwitchboardpublic static NetworkConnection open(java.net.InetAddress address, int port, boolean block) throws java.io.IOException
block is false then the call will return directly
 and the progress can be monitored via the
 Switchboard.notifyWhenConnected
 method.address - IP-address of remote serverport - the port to connect toblock - true if the call should block until the connection
                is establishedjava.io.IOExceptionSwitchboardpublic static NetworkConnection open(Switchboard s, java.net.InetAddress address, int port, boolean block) throws java.io.IOException
block is false then the call will return directly
 and the progress can be monitored via the
 Switchboard.notifyWhenConnected
 method.address - IP-address of remote serverport - the port to connect toblock - true if the call should block until the connection
                is establishedjava.io.IOExceptionSwitchboardpublic Switchboard getSwitchboard()
public void close()
Socketpublic int getPort()
Socketpublic int getLocalPort()
Socketpublic void setTcpNoDelay(boolean delay)
                   throws java.net.SocketException
java.net.SocketExceptionSocketpublic int getSoTimeout()
Socketpublic void setSoTimeout(int timeout)
Socketpublic java.net.InetAddress getInetAddress()
Socketpublic java.net.InetAddress getLocalAddress()
Socketpublic void shutdownOutput()
                    throws java.io.IOException
java.io.IOExceptionSocketpublic NonBlockingInput getInput()
public NonBlockingOutput getOutput()
public java.nio.channels.SocketChannel getChannel()
public java.net.Socket getSocket()
                          throws java.io.IOException
java.io.IOExceptionpublic java.lang.String toString()
toString in class java.lang.Object