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 IMu::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.

  1. The simplest way to create a connection to an IMu server is to pass the host name and port number to the IMu::Session constructor and then call the connect method. For example:
    use IMu::Session;
    # ⋯my $session = IMu::Session->new('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:
    use IMu::Session;
    # ⋯my $session = IMu::Session->new();
    $session->setHost('server.com');
    $session->setPort(12345);
    $session->connect();
    
  3. If either the host or port is not set, the IMu::Session class default value will be used. These defaults can be overridden by setting the (static) class properties defaultHost and defaultPort:
    use IMu::Session;
    # ⋯
    IMu::Session::setDefaultHost('server.com');
    IMu::Session::setDefaultPort(12345);my $session = IMu::Session->new();
    $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 IMu::Handler class.

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

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