|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.mindbright.nio.NetworkConnection
public class NetworkConnection
Holds a non-blocking internet socket.
Constructor Summary | |
---|---|
NetworkConnection(java.nio.channels.SocketChannel channel)
Creates a new NetworkConnection based on the provided SocketChannel. |
|
NetworkConnection(Switchboard s,
java.nio.channels.SocketChannel channel)
|
Method Summary | |
---|---|
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. |
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()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public NetworkConnection(java.nio.channels.SocketChannel channel) throws java.io.IOException
java.io.IOException
public NetworkConnection(Switchboard s, java.nio.channels.SocketChannel channel) throws java.io.IOException
java.io.IOException
Method Detail |
---|
public static NetworkConnection open(java.lang.String host, int port) throws java.io.IOException
Switchboard.notifyWhenConnected
method.
host
- the host nameport
- the port to connect to
java.io.IOException
Switchboard
public 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.
- Parameters:
host
- the host nameport
- the port to connect toblock
- true if the call should block until the connection
is established
- Throws:
java.io.IOException
- See Also:
Switchboard
public 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 to
java.io.IOException
Switchboard
public 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 established
java.io.IOException
Switchboard
public 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 established
java.io.IOException
Switchboard
public Switchboard getSwitchboard()
public void close()
Socket
public int getPort()
Socket
public void setTcpNoDelay(boolean delay) throws java.net.SocketException
java.net.SocketException
Socket
public int getSoTimeout()
Socket
public void setSoTimeout(int timeout)
Socket
public java.net.InetAddress getInetAddress()
Socket
public java.net.InetAddress getLocalAddress()
Socket
public void shutdownOutput() throws java.io.IOException
java.io.IOException
Socket
public NonBlockingInput getInput()
public NonBlockingOutput getOutput()
public java.nio.channels.SocketChannel getChannel()
public java.net.Socket getSocket() throws java.io.IOException
java.io.IOException
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |