com.transjam.client
Class Client

java.lang.Object
  |
  +--com.transjam.util.ClientBase
        |
        +--com.transjam.client.Client
All Implemented Interfaces:
ClientMonitorListener

public class Client
extends ClientBase

TransJam client. Handles basic communication with TransJam server. Keeps track of users in the same room.

Author:
(C) 1997-2002 Phil Burk, SoftSynth.com, All Rights Reserved

Fields inherited from class com.transjam.util.ClientBase
APPLICATION_LEVEL, DEFAULT_TIMEOUT_MSEC, hadError, ifValid, LOBBY_LEVEL, LOGIN_LEVEL, writer
 
Constructor Summary
Client()
          Create client and connect to server on given port.
Client(java.lang.String serverName, int portnum)
           
Client(java.lang.String serverName, int portnum, int timeoutMSec)
           
 
Method Summary
 void addMessageListener(TransjamMessageListener listener)
           
 void addMessageListener(TransjamMessageListener listener, int level)
          Request any messages received from server.
 java.lang.String getUserName(int userID)
           
 void gotMessage(TransjamMessage message)
          Called by ClientMonitor.
 void gotStart()
          Called one when monitor starts.
 void gotStop()
           
 void gotThrowable(java.lang.Throwable exc)
          Called by ClientMonitor.
 void gotTimeout(int numTimeouts)
          A timeout has been detected on a socket input stream read().
 void grantLock(java.lang.String name)
          Give lock to server which has requested it.
 void joinNewRoom(java.lang.String name)
           
 void joinNewRoom(java.lang.String name, int maxClients, int flags)
          Attempt to create a uniquely named room.
 void joinOldRoom(java.lang.String name)
          Attempt to join an existing room.
 void joinRoom(java.lang.String name)
          Attempt to join a room.
 void joinRoom(java.lang.String name, int maxClients, int flags)
          Attempt to join a room.
 void leaveRoom()
          Write a message requesting that to leave the room.
 void lockNewThing(java.lang.String name, java.lang.String contents)
          Attempt to create and lock a uniquely named Thing.
 void lockOldThing(java.lang.String name)
          Attempt to lock an existing Thing.
 void processMessage(TransjamMessage message)
          Handles various messages from server.
 void removeMessageListener(TransjamMessageListener listener)
           
 void removeMessageListener(TransjamMessageListener listener, int level)
           
 void requestLogin(java.lang.String userName)
          Login to server with the given name or handle.
 void requestLogout()
           
 void requestRoomList()
          Ask the server to send a list of users in the room.
 void requestThingList()
          Ask the server to send a list of things in the room.
 void requestTime()
          Request that the server send its UTC time value in milliseconds.
 void requestUserList()
          Ask the server to send a list of users in the room.
 void requestUserLocations()
          Request the location of the current and future users inside a room.
 void sendChat(java.lang.String msg, int flags)
          Send a text message to everyone else in the room.
 void serverDown()
          Thread listening to server caught an IOException.
 void sync()
          Wait for all pending messages to be responded to by server.
 void unlockThing(java.lang.String name)
           
 void write(java.lang.String msg)
           
 
Methods inherited from class com.transjam.util.ClientBase
addMeeting, beginGracefulShutdown, checkValidationMessage, checkValidity, closeSocket, debugln, deleteThing, denyLock, getName, getSocket, getUserID, isActive, isBroken, joinMeeting, lockThing, modifyThing, replyEcho, requestEcho, requestMeetingList, requestValidation, sendAll, sendInfo, sendOthers, sendSelf, sendSync, sendUser, setActive, setName, setSocket, setUserID, start, stop, writeSocket
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Client

public Client()
       throws java.net.UnknownHostException,
              java.io.IOException
Create client and connect to server on given port.

Client

public Client(java.lang.String serverName,
              int portnum)
       throws java.net.UnknownHostException,
              java.io.IOException

Client

public Client(java.lang.String serverName,
              int portnum,
              int timeoutMSec)
       throws java.net.UnknownHostException,
              java.io.IOException
Method Detail

getUserName

public java.lang.String getUserName(int userID)
Returns:
other users name based on userID

gotTimeout

public void gotTimeout(int numTimeouts)
                throws java.io.IOException
A timeout has been detected on a socket input stream read(). On first timeout, client should request an echo from the server. This informs the server that it is still alive. If more consecutive timeouts occur, assume server dead.
Overrides:
gotTimeout in class ClientBase
Returns:
true to continue, false if we should return an EOF (-1) to the caller.

gotThrowable

public void gotThrowable(java.lang.Throwable exc)
Description copied from class: ClientBase
Called by ClientMonitor.
Overrides:
gotThrowable in class ClientBase
Following copied from class: com.transjam.util.ClientBase
Parameters:
exc -  

gotStart

public void gotStart()
Description copied from interface: ClientMonitorListener
Called one when monitor starts.
Overrides:
gotStart in class ClientBase

gotStop

public void gotStop()
Overrides:
gotStop in class ClientBase

sync

public void sync()
          throws java.lang.InterruptedException,
                 java.io.IOException
Wait for all pending messages to be responded to by server.

addMessageListener

public void addMessageListener(TransjamMessageListener listener,
                               int level)
Request any messages received from server.

removeMessageListener

public void removeMessageListener(TransjamMessageListener listener,
                                  int level)

addMessageListener

public void addMessageListener(TransjamMessageListener listener)

removeMessageListener

public void removeMessageListener(TransjamMessageListener listener)

gotMessage

public void gotMessage(TransjamMessage message)
Description copied from class: ClientBase
Called by ClientMonitor.
Overrides:
gotMessage in class ClientBase
Following copied from class: com.transjam.util.ClientBase
Parameters:
message -  

write

public void write(java.lang.String msg)
           throws java.io.IOException
Overrides:
write in class ClientBase

processMessage

public void processMessage(TransjamMessage message)
                    throws java.io.IOException
Handles various messages from server. Echos are replied to. Other users are tracked as they come and go. Other messages are passed to any listeners added using addMessageListener().

serverDown

public void serverDown()
Thread listening to server caught an IOException. Indicates server is down.

requestLogin

public void requestLogin(java.lang.String userName)
                  throws java.io.IOException
Login to server with the given name or handle.

requestLogout

public void requestLogout()
                   throws java.io.IOException

requestTime

public void requestTime()
                 throws java.io.IOException
Request that the server send its UTC time value in milliseconds.

joinRoom

public void joinRoom(java.lang.String name)
              throws java.io.IOException
Attempt to join a room. If the room does not exist then it will be created.

joinRoom

public void joinRoom(java.lang.String name,
                     int maxClients,
                     int flags)
              throws java.io.IOException
Attempt to join a room. If the room does not exist then it will be created.
Parameters:
maxClients - Maximum number of clients allowed per Room. For chess, this would be two.

joinNewRoom

public void joinNewRoom(java.lang.String name,
                        int maxClients,
                        int flags)
                 throws java.io.IOException
Attempt to create a uniquely named room. If creation fails the server will send DENY_ROOM.
Parameters:
maxClients - Maximum number of clients allowed per Room. For chess, this would be two.

joinNewRoom

public void joinNewRoom(java.lang.String name)
                 throws java.io.IOException

joinOldRoom

public void joinOldRoom(java.lang.String name)
                 throws java.io.IOException
Attempt to join an existing room. If the room does not exist then the server will send DENY_ROOM.
Parameters:
maxClients - Maximum number of clients allowed per Room. For chess, this would be two.

leaveRoom

public void leaveRoom()
               throws java.io.IOException
Write a message requesting that to leave the room.

lockNewThing

public void lockNewThing(java.lang.String name,
                         java.lang.String contents)
                  throws java.io.IOException
Attempt to create and lock a uniquely named Thing. If creation fails the server will send CMD_S_DENY_THING.

lockOldThing

public void lockOldThing(java.lang.String name)
                  throws java.io.IOException
Attempt to lock an existing Thing. If it does not exist then the server will send CMD_S_NO_THING. If it cannot be locked then the server will send CMD_S_DENY_LOCK.

unlockThing

public void unlockThing(java.lang.String name)
                 throws java.io.IOException

grantLock

public void grantLock(java.lang.String name)
               throws java.io.IOException
Give lock to server which has requested it.

requestUserList

public void requestUserList()
                     throws java.io.IOException
Ask the server to send a list of users in the room. The user info will be sent using the CMD_S_ADD_USER command. The list will be terminated with CMD_S_END_LIST. If any new users are added later, the server will send another CMD_S_ADD_USER command. If any users leave the room, the server will send a CMD_S_DELETE_USER command.

requestUserLocations

public void requestUserLocations()
                          throws java.io.IOException
Request the location of the current and future users inside a room. Notification will be sent using a CMD_CS_USER_XY command and sent to the client adapter as gotUserLocation(uid,lat,lon).

requestThingList

public void requestThingList()
                      throws java.io.IOException
Ask the server to send a list of things in the room. The thing's name will be sent using the CMD_S_ADD_THING command. If it is locked, the server will send a CMD_S_GRANT_LOCK command. If the contents are non-null, then a CMD_CS_MODIFY_THING command will be sent. The list will be terminated with CMD_S_END_LIST. If any new things are added later, the server will send more commands. If the thing is unlocked, the server will send a CMD_CS_UNLOCK_THING command.

requestRoomList

public void requestRoomList()
                     throws java.io.IOException
Ask the server to send a list of users in the room. The user info will be sent using the CMD_S_ADD_ROOM command. The list will be terminated with CMD_S_END_LIST. If any new rooms are added later, the server will send another CMD_S_ADD_ROOM command. If the room is deleted, the server will send a CMD_S_DELETE_ROOM command.

sendChat

public void sendChat(java.lang.String msg,
                     int flags)
              throws java.io.IOException
Send a text message to everyone else in the room.