swpchat.client
Class ControlConnection

java.lang.Object
  |
  +--swpchat.client.ServerConnection
        |
        +--swpchat.client.ControlConnection
All Implemented Interfaces:
ChatTokens, ControlClient, ControlTokens, FileTransferTokens, ProtocolTokens, SenderReceiverTokens

public class ControlConnection
extends ServerConnection
implements ControlClient, ControlTokens, FileTransferTokens

The controler connection to the server. This class handles all net traffic that is related to administrate the chat session, such as logging in and out, setting the nickname, adding and removing channels...


Field Summary
private  java.io.BufferedWriter bufWriter
           
private  ClientControls clientControls
           
private static java.lang.String CLS
           
private  boolean connected
           
private  ControlReceiver controlReceiver
           
private  java.lang.String sessionKey
           
private  java.net.Socket socket
           
private  ChatStreamTokenizer tokenizer
           
private  java.util.Vector tokenlist
           
private  java.lang.String True_Bool
           
 
Fields inherited from interface swpchat.protocol.ControlTokens
STR_EMOTION, STR_LOGIN, STR_LOGIN_BEGIN, STR_LOGIN_RE_BEGIN, STR_LOGOUT, STR_LOGOUT_BEGIN, STR_LOGOUT_RE_BEGIN, STR_MEMBER, STR_MEMBER_BEGIN, STR_MEMBER_INFO, STR_MEMBER_JOIN, STR_MEMBER_LEAVE, STR_MEMBER_SHIP, STR_NEW_CHANNEL, STR_NOTIFICATION, STR_NOTIFICATION_BEGIN, STR_NOTIFY_REQUEST, STR_REMOVE_CHANNEL, STR_RENAME_CHANNEL, STR_REQUEST_IP, STR_REQUST_IP_RE_BEGIN, STR_SEND_USERINFO, STR_SET_NICK, STR_SET_NICK_BEGIN, STR_SET_NICK_RE_BEGIN, STR_SET_SESSIONKEY, STR_STOP_NOTIFICATION, STR_TELEPHONE_REQUEST
 
Fields inherited from interface swpchat.protocol.ChatTokens
CHAR_ARG_SEP, CHAR_MSG_END, CHAR_MSG_EOL, CHAR_QUOTE, CHAR_STRING_DELIMITER, STR_ARG_SEP, STR_AUTHORIZE, STR_MSG_END, STR_MSG_EOL, STR_NEG_ARG, STR_NEGATIVE, STR_POS_ARG, STR_POSITIVE, STR_QUOTE, STR_REPLY, STR_STRING_DELIMITER, STR_WAIT
 
Fields inherited from interface swpchat.protocol.FileTransferTokens
STR_SEND_FILE_REQUEST, STR_SEND_FILE_REQUEST_BEGIN, STR_SET_FILENAME, STR_SET_FILENAME_BEGIN, STR_SET_FILESIZE, STR_SET_FILESIZE_BEGIN
 
Fields inherited from interface swpchat.protocol.SenderReceiverTokens
STR_JOIN, STR_JOINPASSWD, STR_LEAVE, STR_OFF, STR_ON, STR_PLAY, STR_PLAY_BEGIN, STR_PLAY_RE_BEGIN, STR_RECEIVE, STR_RECEIVE_BEGIN, STR_RECEIVE_USERINFO, STR_REQUEST_USERINFO, STR_SEND, STR_SEND_BEGIN, STR_SEND_RE_BEGIN, STR_SETTOPIC, STR_SETTOPIC_BEGIN, STR_SHIP, STR_SHIP_BEGIN, STR_TOPICCHANGED, STR_WHISPER, STR_WHISPRECEIVE
 
Fields inherited from interface swpchat.protocol.ProtocolTokens
STR_CONTROL, STR_CONTROL_PROTOCOL_ID, STR_FILE_SEND, STR_FILE_SEND_PROTOCOL_ID, STR_PROTOCOL, STR_PROTOCOL_ID_BEGIN, STR_RECEIVER, STR_RECEIVER_PROTOCOL_ID, STR_SENDER, STR_SENDER_PROTOCOL_ID
 
Constructor Summary
ControlConnection(ClientControls clientControls)
          Constructor.
 
Method Summary
 void changeNick(java.lang.String sessionKey, java.lang.String newNick)
          Change the nickname.
private  void changeNickEvenIfUnconnected(java.lang.String sessionKey, java.lang.String newNick)
          Change the nickname without checking connectedness.
 void connect(java.lang.String servername, java.lang.String nickname)
          Connect to the server.
 void createNewChannel(java.lang.String name, java.lang.String sendPasswd, java.lang.String recvPasswd)
          sends a create new channel request to the server.
 void disconnect()
          Disconnect from the server.
 java.lang.String getIPAddress(java.lang.String nickname)
          requestIPAddress from the server
 java.lang.String getSessionKey()
          Gets the actual session key and returns it.
 void handleNormalReceiving(java.util.Vector tokenlist)
          Handles all received messages a receiver control connection would handle, such as newChannel or removeChannel.
 boolean isConnected()
          Checks if the control unit is connected to the server.
 void memberRequest(java.lang.String channel, java.lang.String reason)
          Used to pass the Member Message to the Server,showing the readiness to receive Member Info Messages
 void notificationRequest(java.lang.String nick)
          Send a notificationRequest to the server
 void removeChannel(java.lang.String name)
          removes an existing channel, but not used yet.
 void renameChannel(java.lang.String oldname, java.lang.String newname)
          renames an existing channel, but not used yet.
 void sendContactList()
           
 java.lang.String sendTelephoneRequest(java.lang.String partner, java.lang.String reason)
          Send telephonerequest to the server.
 void sendUserInfo(java.lang.String strUserInfo)
          sends a "sendUserInfo" - command to the server with serveral userInfos serialized to a string
 void stopNotification(java.lang.String nick)
          Send a StopNotification to the server
private  java.lang.Boolean StringToBool(java.lang.String string)
           
 
Methods inherited from class swpchat.client.ServerConnection
isEmotion, isEmotionReceive, isEmotionReply, isJoinReply, isLeaveReply, isLoginReply, isLogoutReply, isMemberInfo, isNegativeRequestUserInfoReply, isNegativeSendUserInfoReply, isNewChannel, isNewChannelReply, isNotification, isPlay, isPlayReply, isPositiveRequestUserInfoReply, isPositiveSendUserInfoReply, isReceive, isReceiveUserInfo, isRemoveChannel, isRemoveChannelReply, isRenameChannel, isRenameChannelReply, isRequestIPAddress, isRequestIPAddressReply, isSendReply, isSendTelephoneRequest, isSendTelephoneRequestReply, isSetNickReply, isSetSessionKeyReply, isSetTopicReply, isShipReceive, isShipReply, isTopicChanged, isWhisperReply, isWhispreceive, readReply, reply, send, send, send, send, writeLine
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

CLS

private static final java.lang.String CLS

socket

private java.net.Socket socket

bufWriter

private java.io.BufferedWriter bufWriter

tokenizer

private ChatStreamTokenizer tokenizer

tokenlist

private java.util.Vector tokenlist

controlReceiver

private ControlReceiver controlReceiver

clientControls

private ClientControls clientControls

sessionKey

private java.lang.String sessionKey

connected

private boolean connected

True_Bool

private final java.lang.String True_Bool
Constructor Detail

ControlConnection

public ControlConnection(ClientControls clientControls)
Constructor.
Method Detail

connect

public void connect(java.lang.String servername,
                    java.lang.String nickname)
             throws ServiceRefusedException,
                    TimeoutException,
                    java.io.IOException
Connect to the server.
Specified by:
connect in interface ControlClient
Parameters:
servername - The server to connect to.
nickname - The user's choosen nickname.
Throws:
ServiceRefusedException - If the server refused the login request.
TimeoutException - If the server does not send the receipt within a certain timeout.
java.io.IOException - For problems in lower layers.

changeNick

public void changeNick(java.lang.String sessionKey,
                       java.lang.String newNick)
                throws ServiceRefusedException,
                       NotConnectedException,
                       TimeoutException,
                       java.io.IOException,
                       java.net.ProtocolException
Change the nickname.
Specified by:
changeNick in interface ControlClient
Throws:
ServiceRefusedException - If the nickname could not be changed.
NotConnectedException - The client is not connected to the server.
TimeoutException - If the server does not send the receipt within a certain timeout.
java.io.IOException - For problems in lower layers.
java.net.ProtocolException - If receiving an unexpected answer.

changeNickEvenIfUnconnected

private void changeNickEvenIfUnconnected(java.lang.String sessionKey,
                                         java.lang.String newNick)
                                  throws ServiceRefusedException,
                                         TimeoutException,
                                         java.io.IOException,
                                         java.net.ProtocolException
Change the nickname without checking connectedness. This can be used here to set the nickname during login.

getIPAddress

public java.lang.String getIPAddress(java.lang.String nickname)
                              throws ServiceRefusedException,
                                     TimeoutException,
                                     java.io.IOException,
                                     java.net.ProtocolException
requestIPAddress from the server
Parameters:
nickname - identyfies the owner of the requested IPAddress
Returns:
the requested IPAddress

sendTelephoneRequest

public java.lang.String sendTelephoneRequest(java.lang.String partner,
                                             java.lang.String reason)
                                      throws ServiceRefusedException,
                                             TimeoutException,
                                             java.io.IOException,
                                             java.net.ProtocolException
Send telephonerequest to the server. Returns the IP of the partner.
Parameters:
partner - the nickname of the partner who is desired to be talked with
reason - the reason, the desired partner gets to see
Throws:
ServiceRefusedException - If the server rejected the send request.
TimeoutException - If the server does not send the receipt within a certain timeout.
java.io.IOException - For problems in lower layers.
java.net.ProtocolException - For problems with the protocol.

disconnect

public void disconnect()
                throws NotConnectedException,
                       java.io.IOException,
                       TimeoutException,
                       java.net.ProtocolException
Disconnect from the server. After this call, the client is always disconnected, even if an exception has been thrown!
Specified by:
disconnect in interface ControlClient
Throws:
NotConnectedException - If the client has not been connected in the first place.
java.io.IOException - For problems in lower layers. The client is disconnected nonetheless.
TimeoutException - If the server does not respond within the timeout.
java.net.ProtocolException - If receiving an unexpected answer.

createNewChannel

public void createNewChannel(java.lang.String name,
                             java.lang.String sendPasswd,
                             java.lang.String recvPasswd)
                      throws NotConnectedException,
                             java.io.IOException,
                             TimeoutException,
                             ServiceRefusedException
sends a create new channel request to the server.
Specified by:
createNewChannel in interface ControlClient
Parameters:
name - The channel name.
Throws:
NotConnectedException - if we are not connected to the server.
TimeoutException - if the server does not respond within the timeout
ServiceRefusedException - if the server refuses creating a new channel
java.io.IOException - on IO propblems in lower layers

renameChannel

public void renameChannel(java.lang.String oldname,
                          java.lang.String newname)
                   throws NotConnectedException,
                          java.io.IOException,
                          TimeoutException,
                          java.net.ProtocolException,
                          ServiceRefusedException
renames an existing channel, but not used yet.
Specified by:
renameChannel in interface ControlClient
Parameters:
name - The channel name.
Throws:
NotConnectedException - if we are not connected to the server.
TimeoutException - if the server does not respond within the timeout
ServiceRefusedException - if the server refuses creating a new channel
java.io.IOException - on IO propblems in lower layers
java.net.ProtocolException - if we receive an unexpected answer.

removeChannel

public void removeChannel(java.lang.String name)
                   throws NotConnectedException,
                          java.io.IOException,
                          TimeoutException,
                          java.net.ProtocolException,
                          ServiceRefusedException
removes an existing channel, but not used yet.
Specified by:
removeChannel in interface ControlClient
Parameters:
name - The channel name.
Throws:
NotConnectedException - if we are not connected to the server.
TimeoutException - if the server does not respond within the timeout
ServiceRefusedException - if the server refuses creating a new channel
java.io.IOException - on IO propblems in lower layers
java.net.ProtocolException - if we receive an unexpected answer.

sendUserInfo

public void sendUserInfo(java.lang.String strUserInfo)
                  throws NotConnectedException,
                         java.io.IOException,
                         TimeoutException,
                         java.net.ProtocolException,
                         ServiceRefusedException
sends a "sendUserInfo" - command to the server with serveral userInfos serialized to a string
Parameters:
strUserInfo - user info string of this shape: firstname":"Rene":"lastname":"Woerzberger

handleNormalReceiving

public void handleNormalReceiving(java.util.Vector tokenlist)
                           throws java.io.IOException,
                                  java.net.ProtocolException
Handles all received messages a receiver control connection would handle, such as newChannel or removeChannel.
Specified by:
handleNormalReceiving in interface ControlClient
Parameters:
tokenlist - The tokenlist got from InputStream.

StringToBool

private java.lang.Boolean StringToBool(java.lang.String string)

memberRequest

public void memberRequest(java.lang.String channel,
                          java.lang.String reason)
                   throws ServiceRefusedException,
                          TimeoutException,
                          java.io.IOException
Used to pass the Member Message to the Server,showing the readiness to receive Member Info Messages
Parameters:
channel - the Channel we are joined in
reason - of MemberRequest

sendContactList

public void sendContactList()
                     throws TimeoutException,
                            java.io.IOException

notificationRequest

public void notificationRequest(java.lang.String nick)
                         throws TimeoutException,
                                java.io.IOException
Send a notificationRequest to the server
Parameters:
nick - the user you want to be notified of.
Throws:
TimeoutException - thrown if time exceeds
java.io.IOException - Error occured in lower layers.

stopNotification

public void stopNotification(java.lang.String nick)
                      throws TimeoutException,
                             java.io.IOException
Send a StopNotification to the server
Parameters:
nick - the user you donīt want to be notified of anymore.
Throws:
TimeoutException - thrown if time exceeds
java.io.IOException - Error occured in lower layers.

isConnected

public boolean isConnected()
Checks if the control unit is connected to the server.
Specified by:
isConnected in interface ControlClient

getSessionKey

public java.lang.String getSessionKey()
Gets the actual session key and returns it.
Specified by:
getSessionKey in interface ControlClient