Connecting to an IMu server
Most IMu based programs begin by creating a connection to an IMu server.
Connections to a server are created and managed using IMu’s Session
class.
Before connecting, both the name of the host and the port number to connect on
must be specified. This can be done in one of three ways.
- The simplest way to create a connection to an IMu server is to pass the host
name and port number to the
Session
constructor and then call theconnect
method. For example:import com.kesoftware.imu.Session; // ⋯ Session session = new Session("server.com", 12345); session.connect();
- Alternatively, pass no values to the constructor and then set the
host
andport
properties (using thesetHost
andsetPort
methods) before callingconnect
:import com.kesoftware.imu.Session; // ⋯ Session session = new Session(); session.setHost("server.com"); session.setPort(12345); session.connect();
- If either the host or port is not set, the
Session
class default value will be used. These defaults can be overridden by setting the (static) class propertiesdefaultHost
anddefaultPort
:import com.kesoftware.imu.Session; // ⋯ Session.setDefaultHost("server.com"); Session.setDefaultPort(12345); Session session = new Session(); session.connect();
This technique is useful when planning to create several connections to the same server or when wanting to get a Handler object to create the connection automatically.
Handlers
Once a connection to an IMu server has been established, it is possible to create handler objects to submit requests to the server and receive responses.
Note: When a handler object is created, a corresponding object is created by the IMu server to service the handler's requests.
All handlers are subclasses of IMu's Handler
class.
Note: You do not typically create a Handler
object directly but instead
use a subclass.
In this document we examine the most frequently used handler, Module
, which
allows you to find and retrieve records from a single EMu module.