Package ch.marcsladek.jrtnp.client

Source Code of ch.marcsladek.jrtnp.client.Client

package ch.marcsladek.jrtnp.client;

import java.io.IOException;
import java.net.Socket;

import ch.marcsladek.jrtnp.connection.Connection;
import ch.marcsladek.jrtnp.connection.ConnectionFactory;

public class Client {

  protected final Connection server;

  /**
   *
   * @param host
   *          ip the client connects to
   * @param port
   *          port the client connects to
   * @param connectionFactoryClass
   *          class of the factory used to create objects of own Connection
   *          implementation
   * @throws ReflectiveOperationException
   *           when unable to use reflection on given class
   * @throws IOException
   *           when error with socket and stream
   */
  public Client(String host, int port,
      Class<? extends ConnectionFactory> connectionFactoryClass)
      throws ReflectiveOperationException, IOException {
    ConnectionFactory factory = connectionFactoryClass.getConstructor().newInstance();
    server = factory.newInstance(new Socket(host, port));
  }

  /**
   * Starts the listener for the server
   */
  public final void start() {
    server.start();
  }

  /**
   * Stops the listener for the server
   *
   * @throws IOException
   */
  public final void shutdown() throws IOException {
    server.shutdown();
  }

  @Override
  public String toString() {
    return server.toString();
  }

}
TOP

Related Classes of ch.marcsladek.jrtnp.client.Client

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.