package echo; import java.io.*; import java.net.*; import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; import utils.PropertyHandler; /** * Simple Echo Client * * @author wolfdieterotte */ public class EchoClient implements Runnable { // references to receiver/sender static EchoClientThread sender = null; // server connectivity information private static String serverIP = null; private static int serverPort = 0; // socket to server private static Socket socket = null; /** * Constructor, initializing connectivity information to EchoServer * * @param propertiesFile Properties file name */ public EchoClient (String propertiesFile) { Properties properties = null; // open properties try { properties = new PropertyHandler(propertiesFile); } catch (IOException ex) { Logger.getLogger(EchoClient.class.getName()).log(Level.SEVERE, "Cannot open properties file", ex); System.exit(1); } // get server IP try { serverIP = properties.getProperty("SERVER_IP"); } catch (Exception ex) { Logger.getLogger(EchoClient.class.getName()).log(Level.SEVERE, "Cannot read server IP", ex); System.exit(1); } // get server port try { serverPort = Integer.parseInt(properties.getProperty("SERVER_PORT")); } catch (NumberFormatException ex) { Logger.getLogger(EchoClient.class.getName()).log(Level.SEVERE, "Cannot read server port", ex); System.exit(1); } } @Override /** * Implementation of interface Runnable * * Called by main() to start the EchoClientThread */ public void run() { // start the receiver (new EchoClientThread(serverIP, serverPort)).start(); } /** * Get the ball rolling * * @param args * @throws IOException */ public static void main(String[] args) throws IOException { String propertiesFile = null; try { propertiesFile = args[0]; } catch (ArrayIndexOutOfBoundsException ex) { propertiesFile = "config/Server.properties"; } // start EchoClient (new EchoClient(propertiesFile)).run(); } }