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 IMuSession 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.

  1. The simplest way to create a connection to an IMu server is to pass the host name and port number to the IMuSession constructor and then call the connect method. For example:
    require_once '/usr/local/lib/imu/IMu.php';
    require_once IMu::$lib . '/Session.php';
    // ⋯
    $session = new IMuSession('server.com', 12345);
    $session->connect();
    
  2. Alternatively, pass no values to the constructor and then set the host and port properties (using the setHost and setPort methods) before calling connect:
    require_once '/usr/local/lib/imu/IMu.php';
    require_once IMu::$lib . '/Session.php';
    // ⋯
    $session = new IMuSession();
    $session->setHost("server.com");
    $session->setPort(12345);
    $session->connect();
    
  3. If either the host or port is not set, the IMuSession class default value will be used. These defaults can be overridden by setting the (static) class properties defaultHost and defaultPort:
    require_once '/usr/local/lib/imu/IMu.php';
    require_once IMu::$lib . '/Session.php';
    // ⋯
    IMuSession::setDefaultHost('server.com');
    IMuSession::setDefaultPort(12345);
    $session = new IMuSession();
    $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 IMuHandler class.

Note: You do not typically create a IMuHandler object directly but instead use a subclass.

In this document we examine the most frequently used handler, IMuModule, which allows you to find and retrieve records from a single EMu module.