repeat83

EchoClient

Aug 14th, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. import java.io.*;
  2. import java.net.*;
  3.  
  4. public class EchoClient {
  5.  
  6.     public static PrintWriter out;
  7.     public static void main(String[] args) throws IOException {
  8.  
  9.         if (args.length != 2) {
  10.             System.err.println(
  11.                     "Usage: java EchoClient <host name> <port number>");
  12.             System.exit(1);
  13.         }
  14.  
  15.         String hostName = args[0];
  16.         int portNumber = Integer.parseInt(args[1]);
  17.  
  18.         try (
  19.                 Socket echoSocket = new Socket(hostName, portNumber);
  20.                 PrintWriter out =
  21.                         new PrintWriter(echoSocket.getOutputStream(), true);
  22.                 BufferedReader in =
  23.                         new BufferedReader(
  24.                                 new InputStreamReader(echoSocket.getInputStream()));
  25.                 BufferedReader stdIn =
  26.                         new BufferedReader(
  27.                                 new InputStreamReader(System.in));
  28.         ) {
  29.  
  30.             admin t = new admin("repeat","12345678");
  31.             //t.sendTest("\005TST\000!");
  32.             t.connectToChat();
  33.  
  34.             /*
  35.             String userInput;
  36.             while ((userInput = stdIn.readLine()) != null) {
  37.                 out.println(userInput);
  38.                 System.out.println("echo: " + in.readLine());
  39.             }
  40.             */
  41.         } catch (UnknownHostException e) {
  42.             System.err.println("Don't know about host " + hostName);
  43.             System.exit(1);
  44.         } catch (IOException e) {
  45.             System.err.println("Couldn't get I/O for the connection to " +
  46.                     hostName);
  47.             System.exit(1);
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment