swpchat.client
Class SenderServerConnection

java.lang.Object
  |
  +--swpchat.client.ServerConnection
        |
        +--swpchat.client.SenderServerConnection
All Implemented Interfaces:
ChatTokens, ControlTokens, ProtocolTokens, SenderClient, SenderReceiverTokens

public class SenderServerConnection
extends ServerConnection
implements SenderClient

Class for sender communication to the server.


Field Summary
private  ClientControls clientControls
           
(package private) static java.lang.String CLS
           
(package private)  boolean connected
           
private  java.io.BufferedWriter oStream
           
private  java.net.Socket socket
           
private  ChatStreamTokenizer tokenizer
           
private  java.util.Vector tokenlist
           
 
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.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.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.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
SenderServerConnection(ClientControls clientControls)
          Constructor.
 
Method Summary
 void connect(java.lang.String servername, java.lang.String sessionKey)
          Connects to the given server with the given nickname.
 void disconnect()
          Disconnect from the server.
 void emotion(java.lang.String channelName, java.lang.String target, java.lang.String emotion)
          Emotion message to the server.
 boolean isConnected()
          Checks wether the client is connected.
 void join(java.lang.String sessionKey, java.lang.String channelName)
          join specified channel
 void leave(java.lang.String channelName)
          leave the specified channel
 void play(java.lang.String channelName, java.lang.String audioKey)
          Make other clients play a sound file.
 void requestUserInfo(java.lang.String nickname)
          sends a user info request
 void send(java.lang.String channelName, java.lang.String text)
          Send media to the server.
 void setTopic(java.lang.String channelName, java.lang.String topic)
          Set topic for a channel.
 void ship(java.lang.String nick, java.lang.String status, ShipWindow shipWindow)
          Ship media to the server.
 void whisper(java.lang.String channelName, java.lang.String receiver, java.lang.String text)
          Whisper message to the server.
 
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

static final java.lang.String CLS

socket

private java.net.Socket socket

oStream

private java.io.BufferedWriter oStream

tokenizer

private ChatStreamTokenizer tokenizer

tokenlist

private java.util.Vector tokenlist

clientControls

private ClientControls clientControls

connected

boolean connected
Constructor Detail

SenderServerConnection

public SenderServerConnection(ClientControls clientControls)
Constructor. Used to set clientControls.
Method Detail

connect

public void connect(java.lang.String servername,
                    java.lang.String sessionKey)
             throws ServiceRefusedException,
                    TimeoutException,
                    java.io.IOException
Connects to the given server with the given nickname.
Specified by:
connect in interface SenderClient
Parameters:
servername - The name of a spChatServer host, in a notation accepted by Socket.Socket(String,int).
nickname - The desired nickname.
Throws:
ServiceRefusedException - If the server rejected logging in. Generally not being able to open the socket produces some java.net exception.
TimeoutException - If the Server did not react within a certain timeout.
java.io.IOException - For problems in lower layers.

join

public void join(java.lang.String sessionKey,
                 java.lang.String channelName)
          throws ServiceRefusedException,
                 TimeoutException,
                 NotConnectedException,
                 java.io.IOException
join specified channel
Specified by:
join in interface SenderClient
Parameters:
sessionKey - that identifies the client
String - the Channel to join

leave

public void leave(java.lang.String channelName)
           throws ServiceRefusedException,
                  TimeoutException,
                  NotConnectedException,
                  java.io.IOException
leave the specified channel
Specified by:
leave in interface SenderClient
Parameters:
strChannel - the channel to left

send

public void send(java.lang.String channelName,
                 java.lang.String text)
          throws ServiceRefusedException,
                 NotConnectedException,
                 TimeoutException,
                 java.io.IOException
Send media to the server.
Specified by:
send in interface SenderClient
Throws:
ServiceRefusedException - If the server rejected the send request.
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.

setTopic

public void setTopic(java.lang.String channelName,
                     java.lang.String topic)
              throws ServiceRefusedException,
                     NotConnectedException,
                     TimeoutException,
                     java.io.IOException
Set topic for a channel.
Throws:
ServiceRefusedException - If the server rejected the request.
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.

ship

public void ship(java.lang.String nick,
                 java.lang.String status,
                 ShipWindow shipWindow)
          throws ServiceRefusedException,
                 NotConnectedException,
                 TimeoutException,
                 java.io.IOException
Ship media to the server.
Parameters:
The - nick who gets or loses his ships
on - or off
Throws:
ServiceRefusedException - If the server rejected the send request.
NotConnectedException - The client is not connected to the server.
java.io.IOException - For problems in lower layers.

whisper

public void whisper(java.lang.String channelName,
                    java.lang.String receiver,
                    java.lang.String text)
             throws ServiceRefusedException,
                    NotConnectedException,
                    TimeoutException,
                    java.io.IOException
Whisper message to the server.
Throws:
ServiceRefusedException - If the server rejected the send request.
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.

emotion

public void emotion(java.lang.String channelName,
                    java.lang.String target,
                    java.lang.String emotion)
             throws ServiceRefusedException,
                    NotConnectedException,
                    TimeoutException,
                    java.io.IOException
Emotion message to the server.
Throws:
ServiceRefusedException - If the server rejected the send request.
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.

isConnected

public boolean isConnected()
Checks wether the client is connected. Currently, this checks only the internal state of the client, not wether the connection is operational.
Specified by:
isConnected in interface SenderClient
Returns:
true If the client (thinks it) is connected to a server.

play

public void play(java.lang.String channelName,
                 java.lang.String audioKey)
          throws ServiceRefusedException,
                 NotConnectedException,
                 TimeoutException,
                 java.io.IOException
Make other clients play a sound file.
Specified by:
play in interface SenderClient
Parameters:
audiokey - The name of the sound to play. The receiving clients maps this name to a sound file and plays that file. Default names include Hello plays a greeting, Laugh plays a laugh and Bye.
Throws:
ServiceRefusedException - If the server rejected the play request.
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.

disconnect

public void disconnect()
                throws java.io.IOException
Disconnect from the server. As a receiver is not really disconnected, this simply handles an internal state.
Specified by:
disconnect in interface SenderClient
Throws:
java.io.IOException - If something broken.

requestUserInfo

public void requestUserInfo(java.lang.String nickname)
                     throws ServiceRefusedException,
                            NotConnectedException,
                            TimeoutException,
                            java.io.IOException
sends a user info request
Parameters:
nickname - the user we want the information from