public class NetPuzlClientProxy extends ServerXMLHandler implements java.lang.Runnable
ServerXMLHandler
Modifier and Type | Field and Description |
---|---|
private Agent |
agent
Agent object of the client connected
|
private java.lang.Thread |
agentThread
Thread for the parser
|
private boolean |
canKillThread
A flag if we can kill this thread.
|
private java.util.Map<ObjID,NetPuzlObject> |
clientCache
The client's cache of NetPuzlObjects and their associated object IDs
|
private java.net.Socket |
clientSocket
Client Socket to communicate with the clients
|
private org.xml.sax.InputSource |
input
input source for the parser
|
private SoftCloseInputStream |
is
Data stream from server
|
private boolean |
isLoggedin
Once the tags come in to check if the client is logged in
|
private NetPuzlServer |
netPuzlServer
The NetPuzlServer of this client proxy
|
private java.io.DataOutputStream |
os
Data Stream to send tags to server
|
private org.xml.sax.XMLReader |
parser
The Server XML Parser
|
private java.lang.String |
username
The received username of the Agent
|
attr
Constructor and Description |
---|
NetPuzlClientProxy(java.net.Socket s,
NetPuzlServer nps)
Starts up a new client proxy
|
Modifier and Type | Method and Description |
---|---|
boolean |
canKill()
Returns true if the thread is ready to be killed
|
private void |
disconnectProcess(java.lang.String msg)
Attempts to close the connection properly, by sending a logged-in,
logged-out tag and the closing server tag.
|
protected void |
endOfXMLDocument()
Shuts down the input since the end of XML document have been reached or
closes the socket if the output have already been shutdown
|
private void |
flushOutput()
Flushes the output stream on a client socket
|
Agent |
getAgent()
Returns the agent
|
NetPuzlServer |
getNetPuzlServer()
Gets the NetPuzlServer of this NetPuzl client proxy
|
java.lang.String |
getUserName()
Returns the username
|
private void |
initAgentThread() |
boolean |
isLoggedIn()
Returns true if is logged-in, false otherwise
|
void |
killThread() |
protected void |
receivedCmd(TCmd tag)
Called by XMLHandler when cmd tag received.
|
protected void |
receivedLogin(TLogin tag)
Called by XMLHandler when login tag received.
|
protected void |
receivedLogout(TLogout logoutTag)
Called by XMLHandler when logout tag received.
|
protected void |
receivedXrequest(TXrequest tag)
Method is called when Tag type XREQUEST is received from the client.
|
void |
run()
Runs the parser
|
private boolean |
sendToClient(java.lang.String msg)
Sends the actual string to the client, also appends it to the log of send
XML Document
|
boolean |
sendToClient(Tag tag)
Method designed to send XML tags over the network to the client Checks
the cache if the client knows about the change in his matrix
|
java.lang.String |
toString()
Client Proxy to string
|
endElement, getHeader, parseClientTag, parseCmdTag, parseLoginTag, parseLogoutTag, parseTag, parseXrequestTag
characters, convertToColor, endDocument, getData, getType, getVersion, parseHexImage, startElement
private NetPuzlServer netPuzlServer
private java.util.Map<ObjID,NetPuzlObject> clientCache
private org.xml.sax.XMLReader parser
private java.io.DataOutputStream os
private SoftCloseInputStream is
private java.net.Socket clientSocket
private org.xml.sax.InputSource input
private java.lang.Thread agentThread
private boolean isLoggedin
private java.lang.String username
private Agent agent
private boolean canKillThread
public NetPuzlClientProxy(java.net.Socket s, NetPuzlServer nps)
s
- the socket of the end point the client is connecting tonps
- the server stateprivate void initAgentThread()
private void disconnectProcess(java.lang.String msg)
msg
- message that will be included in the logged-out tagprotected void endOfXMLDocument()
endOfXMLDocument
in class XMLHandler
private void flushOutput()
public Agent getAgent()
public NetPuzlServer getNetPuzlServer()
public java.lang.String getUserName()
public boolean isLoggedIn()
public boolean canKill()
public void killThread()
protected void receivedCmd(TCmd tag) throws org.xml.sax.SAXException
receivedCmd
in class ServerXMLHandler
tag
- Tag that was receivedorg.xml.sax.SAXException
TCmd
protected void receivedLogin(TLogin tag) throws org.xml.sax.SAXException
receivedLogin
in class ServerXMLHandler
tag
- Tag that was receivedorg.xml.sax.SAXException
- if agent is already logged-inTLogin
protected void receivedLogout(TLogout logoutTag) throws org.xml.sax.SAXException
receivedLogout
in class ServerXMLHandler
logoutTag
- Tag that was receivedorg.xml.sax.SAXException
- if agent is not logged-inTLogout
protected void receivedXrequest(TXrequest tag) throws org.xml.sax.SAXException
ServerXMLHandler
receivedXrequest
in class ServerXMLHandler
tag
- Tag that was receivedorg.xml.sax.SAXException
- if problem with parsing a tag has occurredTXrequest
public void run()
run
in interface java.lang.Runnable
private boolean sendToClient(java.lang.String msg)
msg
- tag to be send.public boolean sendToClient(Tag tag)
tag
- to be sendpublic java.lang.String toString()
toString
in class java.lang.Object