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.

  1. 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 the Connect method. For example:

    C#

    using IMu;
    // ⋯
    Session session = new Session("server.com", 12345);
    session.Connect();
    

    VB

    Imports IMu
    ' ⋯
    Dim session = New Session("server.com", 12345)
    session.Connect()
    
  2. Alternatively, pass no values to the constructor and then set the Host and Port properties before calling Connect:

    C#

    using IMu;
    // ⋯
    Session session = new Session();
    session.Host = "server.com";
    session.Port = 12345;
    session.Connect();
    

    VB

    Imports IMu
    ' ⋯
    Dim session as Session = New Session
    session.Host = "server.com"
    session.Port = 12345
    session.Connect()
    
  3. 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 properties DefaultHost and DefaultPort:

    C#

    using IMu;
    // ⋯
    Session.DefaultHost = "server.com";
    Session.DefaultPort = 12345;
    Session session = new Session();
    session.Connect();
    

    VB

    Imports IMu' ⋯
    Session.DefaultHost = "server.com"
    Session.DefaultPort = 12345
    Dim 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.