public class NetPuzlClient extends ClientXMLHandler implements java.lang.Runnable
ClientXMLHandler
Modifier and Type | Field and Description |
---|---|
private ObjID |
agentId
The ObjID of the agent that is assiciated with this client
|
private java.util.Map<ObjID,NetPuzlObject> |
cache
The cache/symbol table of NetPuzlObjects and their associated object IDs
|
private java.util.Calendar |
cal
A Calender used for logs
|
private java.lang.Thread |
clientThread
New thread which fires up the XML Parser
|
private ClientMatrix |
currentMatrix
The matrix this client is connected to
|
private java.lang.String |
group
The group name whose sever you are connecting to
|
private Gui |
gui
A reference to the Gui that is displaying for this client
|
private org.xml.sax.InputSource |
input
InputStream for the parser
|
private SoftCloseInputStream |
is
Get input stream from server
|
private boolean |
isConnected
A boolean to tell if you are connected to the server
|
private boolean |
isLoggedIn
A boolean to tell if the client is logged in or not
|
private java.io.FileOutputStream |
logOS
Logs the document being send to the server
|
private java.io.DataOutputStream |
os
Write to the server
|
private org.xml.sax.XMLReader |
parser |
private java.text.SimpleDateFormat |
sdf
A SimpleDateFormat used for logs
|
private java.net.Socket |
serverSocket
Client socket used to communicate with server
|
private TServer.SStatus |
serverStatus
The connection status of the server
|
attr
Constructor and Description |
---|
NetPuzlClient(java.lang.String serverAddress,
int port)
Constructs the NetPuzlClient, by connecting to the NetPuzl server and
starting the XML Parser for communication.
|
Modifier and Type | Method and Description |
---|---|
private Attributes |
createAttributesFromSetTag(TSet tag)
This method creates a new Attributes used for when you receive a set tag
for an object
|
private void |
createNetPuzlObjectFromTag(TSet tag,
Attributes attributes)
This method creates a NetPuzlObject from a TSet tag and an Attributes.
|
protected void |
endOfXMLDocument()
Closes the socket, since server closing tag is the last piece of the
communication.
|
private void |
errorDisconnect(java.lang.String msg)
Attempts to close the connection properly if the server status is opened,
by sending a logout tag and the closing client tag ie.
|
private void |
flushOutput()
Flushes the server OuputStream os.
|
ObjID |
getAgentId()
Returns current agent
|
java.util.Map<ObjID,NetPuzlObject> |
getCache()
Returns the cache
|
ClientMatrix |
getCurrentMatrix()
Returns current matrix
|
boolean |
getLoggedIn()
Returns login status
|
TServer.SStatus |
getServerStatus()
Returns a status of the server
|
private void |
initThread() |
boolean |
isConnected()
Returns the connection status
|
static void |
main(java.lang.String[] args)
Starts the client
|
protected void |
receivedHearTag(THear tag)
Method is called when Tag type HEAR is received from the server.
|
protected void |
receivedLoggedInTag(TLoggedIn tag)
Method is called when Tag type LOGGED_IN is received from the server.
|
protected void |
receivedLoggedOutTag(TLoggedOut tag)
Method is called when Tag type LOGGED_OUT is received from the server.
|
protected void |
receivedServerTag(TServer tag)
Method is called when Tag type SERVER is received from the server.
|
protected void |
receivedSetTag(TSet tag)
Method is called when Tag type SET is received from the server.
|
protected void |
receivedXresponseTag(TXresponse tag)
Method is called when Tag type XRESPONSE is received from the server.
|
void |
run()
Runs the parser
|
private boolean |
sendToServer(java.lang.String msg)
Sends a string to the server
|
boolean |
sendToServer(Tag tag)
Send a tag to the server
|
void |
setCurrentMatrix(ClientMatrix currentMatrix) |
private boolean |
startConnection(java.lang.String _str_serverAddress,
int port)
Start a connection to the server
|
endElement, getHeader, parseHearTag, parseLoggedInTag, parseLoggedOutTag, parseServerTag, parseSetTag, parseTag, parseXresponseTag
characters, convertToColor, endDocument, getData, getType, getVersion, parseHexImage, startElement
private java.lang.Thread clientThread
private java.io.DataOutputStream os
private java.io.FileOutputStream logOS
private SoftCloseInputStream is
private org.xml.sax.InputSource input
private java.net.Socket serverSocket
private org.xml.sax.XMLReader parser
private ClientMatrix currentMatrix
private ObjID agentId
private boolean isLoggedIn
private TServer.SStatus serverStatus
private boolean isConnected
private java.util.Map<ObjID,NetPuzlObject> cache
private Gui gui
private java.util.Calendar cal
private java.text.SimpleDateFormat sdf
private java.lang.String group
public NetPuzlClient(java.lang.String serverAddress, int port) throws java.io.IOException
serverAddress
- address of the serverport
- server is listening onjava.io.IOException
- if cannot connect to the serverpublic static void main(java.lang.String[] args)
args
- Command like arguments are not usedprivate void initThread()
private Attributes createAttributesFromSetTag(TSet tag)
tag
- The TSet tag that is used for setting the attributesprivate void createNetPuzlObjectFromTag(TSet tag, Attributes attributes)
tag
- The set tag used for creationattributes
- The Attributes used for creationprotected void endOfXMLDocument()
endOfXMLDocument
in class XMLHandler
private void errorDisconnect(java.lang.String msg)
msg
- message that will be included in the logout tagprivate void flushOutput()
public ObjID getAgentId()
public java.util.Map<ObjID,NetPuzlObject> getCache()
public ClientMatrix getCurrentMatrix()
public boolean getLoggedIn()
public TServer.SStatus getServerStatus()
public boolean isConnected()
protected void receivedHearTag(THear tag)
ClientXMLHandler
receivedHearTag
in class ClientXMLHandler
tag
- Tag that was receivedcom.putable.xmlhandler.ClientXMLHandler#receiveHearTag
protected void receivedLoggedInTag(TLoggedIn tag)
ClientXMLHandler
receivedLoggedInTag
in class ClientXMLHandler
tag
- Tag that was receivedClientXMLHandler.receivedLoggedInTag(com.putable.common.tags.TLoggedIn)
protected void receivedLoggedOutTag(TLoggedOut tag)
ClientXMLHandler
receivedLoggedOutTag
in class ClientXMLHandler
tag
- Tag that was receivedClientXMLHandler.receivedLoggedOutTag(com.putable.common.tags.TLoggedOut)
protected void receivedServerTag(TServer tag)
ClientXMLHandler
receivedServerTag
in class ClientXMLHandler
tag
- Tag that was receivedClientXMLHandler.receivedServerTag(com.putable.common.tags.TServer)
protected void receivedSetTag(TSet tag)
ClientXMLHandler
receivedSetTag
in class ClientXMLHandler
tag
- Tag that was receivedClientXMLHandler.receivedSetTag(com.putable.common.tags.TSet)
protected void receivedXresponseTag(TXresponse tag)
ClientXMLHandler
receivedXresponseTag
in class ClientXMLHandler
tag
- Tag that was receivedClientXMLHandler.receivedXresponseTag(com.putable.common.tags.TXresponse)
public void run()
run
in interface java.lang.Runnable
private boolean sendToServer(java.lang.String msg)
public boolean sendToServer(Tag tag)
public void setCurrentMatrix(ClientMatrix currentMatrix)
currentMatrix
- the currentMatrix to setprivate boolean startConnection(java.lang.String _str_serverAddress, int port)