inf1010.pusle.chat.client
Class ChatClient

java.lang.Object
  extended by inf1010.pusle.chat.client.ChatClient
All Implemented Interfaces:
ChatListener, java.lang.Runnable

public class ChatClient
extends java.lang.Object
implements java.lang.Runnable, ChatListener

A simple chat client for Puslegruppa.


Constructor Summary
ChatClient(java.lang.String server, int port, java.lang.String user)
          Create a ChatClient and connect it to a server.
 
Method Summary
 void addChatListener(ChatListener listener)
          Changes this client's ChatListener.
 boolean handleMessage(Message m)
          Handles incoming packets not handled by other ChatListeners.
static void main(java.lang.String[] args)
          Entry point.
 void run()
          Listen to the socket until the socket gets closed.
 void sendMessage(java.lang.String msg)
          Sends a chat message to the server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChatClient

public ChatClient(java.lang.String server,
                  int port,
                  java.lang.String user)
Create a ChatClient and connect it to a server.

Parameters:
server - the server to connect to.
port - the port number to use.
user - the username to use in the chat.
Method Detail

main

public static void main(java.lang.String[] args)
Entry point.

Parameters:
args - command line args:
  • server
  • port
  • username

handleMessage

public boolean handleMessage(Message m)
                      throws java.io.IOException
Handles incoming packets not handled by other ChatListeners.

Specified by:
handleMessage in interface ChatListener
Parameters:
m - the packet to handle.
Returns:
true if the message was handled.
Throws:
java.io.IOException - if sending error messages to the user fails.

sendMessage

public void sendMessage(java.lang.String msg)
Sends a chat message to the server.

Parameters:
msg - the message to send to the server.

addChatListener

public void addChatListener(ChatListener listener)
Changes this client's ChatListener.

Parameters:
listener - the new ChatListener to handle received messages.

run

public void run()
Listen to the socket until the socket gets closed.

Specified by:
run in interface java.lang.Runnable