|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object soc.server.genericServer.StringConnection soc.server.genericServer.Connection
public final class Connection
A client's connection at a server.
This class has a run method, but you must start the thread yourself. Constructors will not create or start a thread.
As used within JSettlers, the structure of this class has much in common
with LocalStringConnection
, as they both subclass StringConnection
.
If you add something to one class, you should probably add it to the other, or to the superclass instead.
Refactored in v1.2.0 to extend StringConnection
instead of Thread.
Nested Class Summary | |
---|---|
(package private) class |
Connection.Putter
Connection inner class thread to send outQueue messages to the net. |
Field Summary | |
---|---|
protected boolean |
connected
|
protected java.lang.String |
hst
Hostname of the remote end of the connection, for host() |
(package private) java.io.DataInputStream |
in
|
protected boolean |
inputConnected
|
(package private) java.io.DataOutputStream |
out
|
private java.util.Vector<java.lang.String> |
outQueue
|
(package private) static int |
putters
|
(package private) static java.lang.Object |
puttersMonitor
|
(package private) java.net.Socket |
s
|
protected static int |
TIMEOUT_VALUE
|
Fields inherited from class soc.server.genericServer.StringConnection |
---|
appData, connectTime, data, error, hideTimeoutMessage, localeStr, ourServer, remoteVersion, remoteVersionKnown, remoteVersionTrack, stringMgr |
Constructor Summary | |
---|---|
Connection(java.net.Socket so,
Server sve)
initialize the connection data |
Method Summary | |
---|---|
boolean |
connect()
Set up to reading from the net, start a new Putter thread to send to the net; called only by the server. |
void |
disconnect()
close the socket, stop the reader; called after conn is removed from server structures |
void |
disconnectSoft()
Accept no further input, allow output to drain, don't immediately close the socket. |
java.lang.String |
getName()
Get our connection thread name for debugging. |
java.lang.String |
host()
|
boolean |
isConnected()
Are we currently connected and active? |
boolean |
isInputAvailable()
Is input available now, without blocking? Same idea as FilterInputStream.available() . |
void |
put(java.lang.String str)
Send this data over the connection. |
private boolean |
putAux(java.lang.String str)
put a message on the net |
private boolean |
putForReal(java.lang.String str)
Data is added asynchronously (sitting in outQueue ). |
void |
run()
continuously read from the net |
java.lang.String |
toString()
toString includes data.toString for debugging, and getName() . |
Methods inherited from class soc.server.genericServer.StringConnection |
---|
getAppData, getConnectTime, getData, getError, getI18NLocale, getLocalized, getLocalized, getLocalizedSpecial, getVersion, isVersionKnown, setAppData, setData, setHideTimeoutMessage, setI18NStringManager, setVersion, setVersion, setVersionTracking, wantsHideTimeoutMessage |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
static int putters
static java.lang.Object puttersMonitor
protected static final int TIMEOUT_VALUE
java.io.DataInputStream in
java.io.DataOutputStream out
java.net.Socket s
protected java.lang.String hst
host()
protected boolean connected
protected boolean inputConnected
disconnectSoft()
private java.util.Vector<java.lang.String> outQueue
Constructor Detail |
---|
Connection(java.net.Socket so, Server sve)
Method Detail |
---|
public java.lang.String getName()
toString()
.
public java.lang.String host()
host
in class StringConnection
public boolean connect()
connect()
, be sure to call run()
to start the inbound reading thread.
connect
in class StringConnection
public boolean isInputAvailable()
FilterInputStream.available()
.
isInputAvailable
in class StringConnection
public void run()
run
in interface java.lang.Runnable
run
in class StringConnection
public final void put(java.lang.String str)
outQueue
to be sent by the Putter thread.
put
in class StringConnection
str
- Data to sendprivate boolean putForReal(java.lang.String str)
outQueue
).
This method is called when it's dequeued and sent over
the connection to the remote end.
str
- Data to send
StringConnection.error
)private final boolean putAux(java.lang.String str)
StringConnection.error
)public void disconnect()
disconnect
in class StringConnection
public void disconnectSoft()
isConnected()
will return false, even if output is still being
sent to the other side.
disconnectSoft
in class StringConnection
public boolean isConnected()
isConnected
in class StringConnection
public java.lang.String toString()
getName()
.
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |