|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.antelmann.net.SocketConnection
@Todo(value="support streaming via e.g. BinaryData") public class SocketConnection
A SocketConnection provides simplified access to a remote process through a Socket connection. To create a SocketConnection, use createNetConnection()
NetConnectionServer,
NetConnectionHandler,
ConnectionDispatcher,
NetConnection| Field Summary | |
|---|---|
protected boolean |
autoReset
|
protected InetAddress |
host
|
protected Handshake |
hs
|
protected ObjectInputStream |
in
|
protected Logger |
logger
|
protected ObjectOutputStream |
out
|
protected int |
port
|
protected Socket |
socket
|
| Constructor Summary | |
|---|---|
protected |
SocketConnection(Socket socket,
Handshake hs)
|
| Method Summary | |
|---|---|
void |
close()
closes the SocketConnection |
static SocketConnection |
createConnection(String hostname,
int port)
|
static SocketConnection |
createConnection(String hostname,
int port,
Handshake hs)
returns a SocketConnection provided there is a Server listening at the specified location with the secified signature; note that this method is blocking. |
static SocketConnection |
createServerConnection(int port,
Handshake hs)
|
static SocketConnection |
createServerConnection(ServerSocket serverSocket,
Handshake hs)
waits and listens for a single connection to be made and returns a SocketConnection if the connection made matches the signature. |
static SocketConnection |
createServerConnection(Socket socket,
Handshake hs)
creates a connection based on a socket that results from a ServerSocket.accept() |
Handshake |
getHandshake()
returns the identification type object for this connection; this signature is the same on both sides of the connection. |
int |
getLocalPort()
|
Logger |
getLogger()
loggs standard events - no exceptions are logged here |
InetAddress |
getRemoteHost()
|
int |
getRemotePort()
|
Socket |
getSocket()
returns the underlying Socket of this connection |
boolean |
isActive()
returns whether this NetConnection is currently active |
boolean |
isAutoReset()
|
Object |
readMessage()
reads an object from the connection (operation blocks until object is read) |
void |
reconnect()
applies to the client side of a connection rather than a server |
void |
reconnect(int timeout)
applies to the client side of a connection rather than a server; the timeout only appies to the handshake. |
void |
reset()
performs a manual reset() on the ObjectOutputStream. |
void |
sendMessage(Object message)
sends an object over the connection |
void |
setAutoReset(boolean flag)
|
void |
setLogger(Logger logger)
|
void |
setSoTimeout(int timeout)
propagates to the embedded socket |
String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected Socket socket
protected InetAddress host
protected int port
protected ObjectInputStream in
protected ObjectOutputStream out
protected Handshake hs
protected Logger logger
protected boolean autoReset
| Constructor Detail |
|---|
protected SocketConnection(Socket socket,
Handshake hs)
throws IOException
IOException| Method Detail |
|---|
public static SocketConnection createServerConnection(int port,
Handshake hs)
throws IOException,
HandshakeException
IOException
HandshakeException
public static SocketConnection createServerConnection(ServerSocket serverSocket,
Handshake hs)
throws IOException,
HandshakeException
HandshakeException - if the signatures did not match
IOException
public static SocketConnection createServerConnection(Socket socket,
Handshake hs)
throws IOException,
HandshakeException
IOException
HandshakeException
public static SocketConnection createConnection(String hostname,
int port)
throws IOException,
HandshakeException
IOException
HandshakeException
public static SocketConnection createConnection(String hostname,
int port,
Handshake hs)
throws IOException,
HandshakeException
hostname - specifies the server to connect toport - specifies the port at the server to connect tohs - an object that identifies the desired type of connection
HandshakeException - if the signatures did not match
IOExceptionNetConnectionServerpublic boolean isActive()
NetConnection
isActive in interface NetConnection
public void reconnect()
throws IOException,
HandshakeException
IOException
HandshakeException
public void reconnect(int timeout)
throws IOException,
HandshakeException
IOException
HandshakeException
public void sendMessage(Object message)
throws IOException
NetConnection
sendMessage in interface NetConnectionIOExceptionpublic void setAutoReset(boolean flag)
public boolean isAutoReset()
public void reset()
throws IOException
reset() on the ObjectOutputStream.
An alternative is to set autoReset on this object to have the stream reset
on each message send.
This is necessary to allow the same object to be written more than once
while the state of the object changes.
IOExceptionsetAutoReset(boolean),
ObjectOutputStream.reset()
public Object readMessage()
throws IOException,
ClassNotFoundException
NetConnection
readMessage in interface NetConnectionIOException
ClassNotFoundException
public void setSoTimeout(int timeout)
throws IOException
IOExceptionpublic Handshake getHandshake()
NetConnection
getHandshake in interface NetConnection
public void close()
throws IOException
close in interface CloseableIOExceptionpublic Logger getLogger()
public void setLogger(Logger logger)
public Socket getSocket()
NetConnection
getSocket in interface NetConnectionpublic InetAddress getRemoteHost()
public int getRemotePort()
public int getLocalPort()
public String toString()
toString in class Object
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||