Connecting a client


The client-side components of a CORK-based application communicate with the server via a class that implements the edu.vt.cs.collab.cork.ReplicatedObjectClient
interface. For servers that use the edu.vt.cs.collab.cork.impl.inet.ServerImpl class, the edu.vt.cs.collab.cork.impl.inet.InetClient provides the implementation of ReplicatedObjectClient.

The constructor for InetClient takes three arguments:
  1. The host on which the CORK server is running
  2. The port on which the CORK server is listening
  3. The type of connection to make. This should generally be either InetClient.SOCKET or InetClient.HTTP. The SOCKET parameter will cause the client to attempt a direct socket connection to the server, while the HTTP parameter will cause the client to communicate with the client via http. Note that http support is experimental.
Once the client has been constructed, it is necessary to log into the serverwith a user id and password, using the ReplicatedObjectClient.login(...) method. By default, CORK server do not implement authentication, so any id/password
pair will work. (Details on authentication support appear in a later section of this document.)
The small program below (Client.java) creates a ReplicatedObjectClient that connects to a CORK server:
     1  import edu.vt.cs.collab.cork.impl.inet.InetClient;
     2  import edu.vt.cs.collab.cork.ReplicatedObjectClient;
     3
     4  /**
     5   * Simple CORK client, with little error handling. Should be
     6   * executed with server host and port number as arguments.
     7   */
     8  public class Client{
     9      /**
    10       * Our replicated object client
    11       */
    12      private ReplicatedObjectClient client = null;
    13
    14      public Client(String host, int port) {
    15          try {
    16              client = new InetClient(host, port, InetClient.SOCKET);
    17              client.login("my-id", "my-password");
    18          }
    19          catch(SecurityException se) {
    20              System.err.println("Login failed: ");
    21              se.printStackTrace();
    22          }
    23          catch(Exception e) {
    24              System.err.println("Client connection error: ");
    25              e.printStackTrace();
    26          }
    27      }
    28
    29      public static void main(String[] args) {
    30          int port = Integer.parseInt(args[1]);
    31          Client c = new Client(args[0], port);
    32      }
    33  }
    34
Note that this program doesn't actually do anything, it simply connects and logs in.


/public/chci/howto/cork/client.html Login | Web Editor | Full Editor
Last modified 5/22/03 4:21 PM by isenhour (history)
Site contents