|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Thread
ctf.network.tcp.Connection
public class Connection
A line-oriented TCP connection. This is a TCP connection capable of sending and receiving '\n'-terminated lines. Transmission is simple (@see send() ). Reception can be done either through polling (@see getLine() ) or a dedicated Rx thread (@see start() ).
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Field Summary |
---|
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
Connection()
Empty constructor |
|
Connection(java.net.Socket socket)
Construct a new (already-opened) connection |
|
Connection(java.net.Socket socket,
int timeout)
Construct a new (already-opened) connection |
|
Connection(java.lang.String host,
int port)
Construct a new connection to a server |
|
Connection(java.lang.String host,
int port,
int timeout,
int retries)
Construct a new connection to a server |
Method Summary | |
---|---|
void |
close()
Close the connection |
java.lang.String |
connectedTo()
|
void |
finalize()
|
java.lang.String |
getLine()
Receive a line (string terminated by newline) from the socket with the newline character removed. |
void |
run()
Continuously poll for '\n'-terminated lines and forward them to the connection's owner. |
void |
send(java.lang.String string)
Send a string of characters across the socket |
void |
sendLine(java.lang.String s)
Send a newline-terminated line across the socket |
void |
setOwner(ConnectionOwner owner)
Who "owns" this connection (receives events)? |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, yield |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Connection()
public Connection(java.lang.String host, int port) throws java.io.IOException, UninitializedSocketException, java.net.UnknownHostException
host
- The IP host to connect toport
- The TCP port to connect to
java.io.IOException
- for general connection problems
UninitializedSocketException
- if socket doesn't initialize
java.net.UnknownHostException
- if the host is unknownpublic Connection(java.lang.String host, int port, int timeout, int retries) throws java.io.IOException, UninitializedSocketException, java.net.UnknownHostException
host
- The IP host to connect toport
- The TCP port to connect totimeout
- Milliseconds to wait for timeout (0 means 'infinite')retries
- How many times to retry for a connection
java.io.IOException
- for general connection problems
UninitializedSocketException
- if socket doesn't initialize
java.net.UnknownHostException
- if the host is unknownpublic Connection(java.net.Socket socket) throws java.io.IOException, UninitializedSocketException
socket
- The socket to connect with
java.io.IOException
- on error getting an I/O stream from Socket
UninitializedSocketException
- if connection not establishedpublic Connection(java.net.Socket socket, int timeout) throws java.io.IOException, UninitializedSocketException
socket
- The socket to connect withtimeout
- Milliseconds to wait for timeout (0 means "infinite")
java.io.IOException
- on error getting an I/O stream from Socket
UninitializedSocketException
- if connection not establishedMethod Detail |
---|
public void finalize()
finalize
in class java.lang.Object
public void close() throws java.io.IOException
java.io.IOException
public void sendLine(java.lang.String s) throws java.io.IOException, SocketClosedException, UninitializedSocketException
java.io.IOException
SocketClosedException
UninitializedSocketException
public void send(java.lang.String string) throws java.io.IOException, SocketClosedException, UninitializedSocketException
string
- The string to send
java.io.IOException
SocketClosedException
UninitializedSocketException
public java.lang.String getLine() throws java.io.IOException, NetworkException, SocketClosedException, UninitializedSocketException
java.io.IOException
NetworkException
SocketClosedException
UninitializedSocketException
public void setOwner(ConnectionOwner owner)
public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public java.lang.String toString()
toString
in class java.lang.Thread
public java.lang.String connectedTo()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |