Interface SocketConnection

All Known Implementing Classes:
AlertCountClient, BroadcastClient, CustomClient, ListClient

public interface SocketConnection

This interface has to be implemented by any client session for communicating with a corresponding session on the server side. This interface helps the user applications to model a client server communication and use it for data exchange.

Every class that implements this interface should register itself with the MainSocketClient, which acts as the communication endpoint between the client and the server. Each session should register itself with a distinct identifier , which will uniquely identify it. This is very important as it is used in routing the data to the appropriate sessions both on the client and server side. The same identifier should be used the corresponding server-side session implementation classes.

The implementing class instance can register itself with the MainSocketClient using the following method:


//UniqueSessionID refers to the unique identifier of the session

//this refers to the session class instance implementing this interface.

There should be a corresponding session implementation on either the Front-end server side or the Back-end server side for this session to communicate. The data can be sent to the server using the send methods present in the MainSocketClient. Whenever a response is received by the client from the server, the MainSocketClient identifies the session for which the data is received using the session identifier. It then invokes the receive(byte[]) method of this interface implemented by the session. Using this simple mechanism data can be effectively exchanged between the client and server sessions.

See Also:
MainSocketClient, PureClientUtils, SocketServerConnectionBE, SocketServerConnectionFE

Method Summary
 void close()
          This method will be called when the session is closed by the client.
 void receive(byte[] data)
          This method will be called whenever the session receives data from the server.

Method Detail


void receive(byte[] data)
This method will be called whenever the session receives data from the server. The data received for this session will be passed as a byte array. The implementing session class can process the data and perform the necessary operations. It is suggested to not to perform any UI updations in the context of the same thread as it might cause some undesirable effects as JFC is not thread safe. Please use the recommended javax.swing.SwingUtilities.invokeLater(Runnable) method for UI updations.

data - The byte array received from the server will be passed.


void close()
This method will be called when the session is closed by the client. When the client is closed either by user intervention or because of server connection closure, this method will be called by the MainSocketClient to perform a clean shutdown of the client processes. The implementing classes can perform their resource cleanup job in this method. It should be stressed to do a proper cleanup while session closing, as any improper cleanup might create problems during Applet reload operation.


Copyright © 2013 ZOHO Corp., All Rights Reserved.