|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object soc.client.SOCPlayerClient.ClientNetwork
public static class SOCPlayerClient.ClientNetwork
Helper object to encapsulate and deal with network connectivity.
Local practice server (if any) is started in startPracticeGame(String, Map)
.
Local tcp server (if any) is started in initLocalServer(int)
.
Network shutdown is disconnect()
or dispose()
.
Before v2.0.00, most of these fields and methods were part of the main SOCPlayerClient
class.
SOCPlayerClient.getNet()
Nested Class Summary | |
---|---|
(package private) static class |
SOCPlayerClient.ClientNetwork.NetReadTask
A task to continuously read from the server socket. |
(package private) class |
SOCPlayerClient.ClientNetwork.SOCPlayerLocalStringReader
For practice games, reader thread to get messages from the practice server to be treated and reacted to. |
Field Summary | |
---|---|
(package private) SOCPlayerClient |
client
|
(package private) boolean |
connected
Are we connected to a TCP server (remote or localTCPServer )?
practiceServer is not a TCP server. |
(package private) java.lang.Exception |
ex
Any network error (TCP communication) received while connecting or sending messages in putNet(String) , or null. |
(package private) java.lang.Exception |
ex_P
Practice-server error (stringport pipes), or null |
private java.lang.String |
host
Hostname we're connected to, or null |
(package private) java.io.DataInputStream |
in
|
protected java.lang.String |
lastMessage_N
For debug, our last messages sent, over the net or practice server (pipes) |
protected java.lang.String |
lastMessage_P
For debug, our last messages sent, over the net or practice server (pipes) |
private SOCServer |
localTCPServer
Client-hosted TCP server. |
(package private) java.io.DataOutputStream |
out
|
private int |
port
TCP port we're connected to; default is SOC_PORT_DEFAULT . |
protected SOCServer |
practiceServer
Server for practice games via prCli ; not connected to the network,
not suited for hosting multi-player games. |
protected StringConnection |
prCli
Client connection to practice server . |
(package private) java.lang.Thread |
reader
|
(package private) java.net.Socket |
s
|
static int |
SOC_PORT_DEFAULT
Default tcp port number 8880 to listen, and to connect to remote server. |
Constructor Summary | |
---|---|
SOCPlayerClient.ClientNetwork(SOCPlayerClient c)
|
Method Summary | |
---|---|
boolean |
anyHostedActiveGames()
Look for active games that we're hosting (state >= START1A, not yet OVER). |
void |
connect(java.lang.String chost,
int sPort)
Attempts to connect to the server. |
protected void |
disconnect()
Disconnect from the net (client of remote server). |
void |
dispose()
Shut down the local TCP server (if any) and disconnect from the network. |
java.lang.String |
getHost()
Hostname of the tcp server we're a client of |
int |
getLocalServerPort()
Get the tcp port number of the local server. |
int |
getPort()
Port number of the tcp server we're a client of; default is SOC_PORT_DEFAULT . |
boolean |
initLocalServer(int tport)
Create and start the local TCP server on a given port. |
boolean |
isConnected()
Are we connected to a tcp server? |
boolean |
isRunningLocalServer()
Are we running a local tcp server? |
boolean |
putLeaveAll()
For shutdown - Tell the server we're leaving all games. |
boolean |
putNet(java.lang.String s)
write a message to the net: either to a remote server, or to localTCPServer for games we're hosting. |
boolean |
putPractice(java.lang.String s)
write a message to the practice server. |
void |
resendNet()
resend the last message (to the network) |
void |
resendPractice()
resend the last message (to the practice server) |
void |
shutdownLocalServer()
Shut down the local TCP server. |
void |
startPracticeGame(java.lang.String practiceGameName,
java.util.Map<java.lang.String,SOCGameOption> gameOpts)
Start a practice game. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int SOC_PORT_DEFAULT
8880 is the default SOCPlayerClient port since jsettlers 1.0.4, per cvs history.
final SOCPlayerClient client
private java.lang.String host
private int port
SOC_PORT_DEFAULT
.
private SOCServer localTCPServer
SOCPlayerClient.GameAwtDisplay.startLocalTCPServer(int)
.
practiceServer
may still be activated at the user's request.
Note that SOCGame.isPractice
is false for localTCPServer's games.
java.net.Socket s
java.io.DataInputStream in
java.io.DataOutputStream out
java.lang.Thread reader
java.lang.Exception ex
putNet(String)
, or null.
If ex != null
, putNet will refuse to send.
The exception's toString()
including its
getMessage()
may be displayed to the user
by SOCPlayerClient.dispose()
; if throwing an error that the user
should see, be sure to set the detail message.
java.lang.Exception ex_P
boolean connected
localTCPServer
)?
practiceServer
is not a TCP server.
ex
protected java.lang.String lastMessage_N
protected java.lang.String lastMessage_P
protected SOCServer practiceServer
prCli
; not connected to the network,
not suited for hosting multi-player games. Use localTCPServer
for those.
SOCMessages of games where SOCGame.isPractice
is true are sent
to practiceServer.
Null before it's started in SOCPlayerClient.startPracticeGame()
.
protected StringConnection prCli
practice server
.
Null before it's started in SOCPlayerClient.startPracticeGame()
.
Last message is in lastMessage_P
; any error is in ex_P
.
Constructor Detail |
---|
public SOCPlayerClient.ClientNetwork(SOCPlayerClient c)
Method Detail |
---|
public void dispose()
public void startPracticeGame(java.lang.String practiceGameName, java.util.Map<java.lang.String,SOCGameOption> gameOpts)
practiceServer
.
practiceGameName
- Game namegameOpts
- Game optionspublic int getLocalServerPort()
isRunningLocalServer()
public void shutdownLocalServer()
public boolean initLocalServer(int tport)
NotifyDialog
with the error message.
public int getPort()
SOC_PORT_DEFAULT
.
public java.lang.String getHost()
public boolean isConnected()
public void connect(java.lang.String chost, int sPort) throws java.lang.IllegalStateException
isConnected()
for success or
failure. Once connected, starts a reader
thread.
The first message over the connection is our version,
and the second is the server's response:
Either SOCRejectConnection
, or the lists of
channels and games (SOCChannels
, SOCGames
).
Since user login and authentication don't occur until a game or channel join is requested, no username or password is needed here.
Before 1.1.06, the server's response was first, and version was sent in reply to server's version.
chost
- Server host to connect to, or null
for localhostsPort
- Server TCP port to connect to; the default server port is SOC_PORT_DEFAULT
.
java.lang.IllegalStateException
- if already connectedSOCServer.newConnection1(StringConnection)
protected void disconnect()
ex
.
dispose()
public boolean isRunningLocalServer()
getLocalServerPort()
,
anyHostedActiveGames()
public boolean anyHostedActiveGames()
SOCPlayerClient.GameAwtDisplay.findAnyActiveGame(boolean)
public boolean putNet(java.lang.String s)
localTCPServer
for games we're hosting.
If ex
!= null, or ! connected
, putNet
returns false without attempting to send the message.
This message is copied to lastMessage_N
; any error sets ex
and calls SOCPlayerClient.dispose()
to show the error message.
s
- the message
SOCPlayerClient.GameManager.put(String, boolean)
public boolean putPractice(java.lang.String s)
localTCPServer
is not
the same as the practice server; use putNet(String)
to send
a message to the local TCP server.
Use putPractice only with practiceServer
.
Before version 1.1.14, this was putLocal.
s
- the message
SOCPlayerClient.GameManager.put(String, boolean)
public void resendNet()
public void resendPractice()
public boolean putLeaveAll()
Since no other state variables are set, call this only right before discarding this object or calling System.exit.
ex_P
)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |