QuickServer
v1.4.7

org.quickserver.net.server
Interface ClientEventHandler

All Known Implementing Classes:
CommandHandler, DefaultClientEventHandler

public interface ClientEventHandler

This interface defines the methods that should be implemented by any class that wants to handle client events.

Recommendations to be followed when implementing ClientEventHandler

If not ClientEventHandler is set for QuickServer then a default implementation DefaultClientEventHandler is used.

Ex:

package echoserver;

import java.net.*;
import java.io.*;
import org.quickserver.net.server.ClientEventHandler;
import org.quickserver.net.server.ClientHandler;

public class EchoEventHandler implements ClientEventHandler {

        public void gotConnected(ClientHandler handler)
                throws SocketTimeoutException, IOException {
                handler.sendSystemMsg("Connection opened : "+
                        handler.getSocket().getInetAddress());

                handler.sendClientMsg("Welcome to EchoServer v1.0 ");
                handler.sendClientMsg("Note: Password = Username");
                handler.sendClientMsg("Send 'Quit' to exit");
        }

        public void lostConnection(ClientHandler handler) 
                throws IOException {
                handler.sendSystemMsg("Connection lost : " + 
                        handler.getSocket().getInetAddress());
        }
        public void closingConnection(ClientHandler handler) 
                throws IOException {
                handler.sendSystemMsg("Connection closing : " + 
                        handler.getSocket().getInetAddress());
        }
}

Since:
1.4.5
Author:
Akshathkumar Shetty

Method Summary
 void closingConnection(ClientHandler handler)
          Method called when client connection is closed.
 void gotConnected(ClientHandler handler)
          Method called when there is a new client connects to the QuickServer.
 void lostConnection(ClientHandler handler)
          Method called when client connection is lost.
 

Method Detail

gotConnected

public void gotConnected(ClientHandler handler)
                  throws java.net.SocketTimeoutException,
                         java.io.IOException
Method called when there is a new client connects to the QuickServer. Can be used to send welcome message to the client and logging.

Throws:
java.net.SocketTimeoutException - if socket times out
java.io.IOException - if io error in socket

lostConnection

public void lostConnection(ClientHandler handler)
                    throws java.io.IOException
Method called when client connection is lost. Don't write to the connection in this method. Its just information, to be used at the Server end. It can be caused due to network errors.

Throws:
java.io.IOException - if io error in socket

closingConnection

public void closingConnection(ClientHandler handler)
                       throws java.io.IOException
Method called when client connection is closed. Don't write to the connection in this method. Its just information, you can use to log time and ip of client closing connection.

Throws:
java.io.IOException - if io error in socket

QuickServer
v1.4.7

Copyright © 2003-2006 QuickServer.org