Package ua

Source Code of ua.SimpleClient

package ua;

import java.io.BufferedReader;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.UnknownHostException;

public class SimpleClient {

  /**
   * @param args
   *            No parameters.
   * @throws IOException
   */
  public static void main(String[] args) throws IOException {
    BufferedReader input = new BufferedReader(new InputStreamReader(
        System.in));
    Socket socket = null;

    do {
      try {
        socket = new Socket("localhost", 23);
        System.out.print("Input command to server: ");
        String commandLine = input.readLine();
        DataOutputStream out = new DataOutputStream(
            socket.getOutputStream());
        out.writeUTF(commandLine);
        out.flush();
        DataInputStream is = new DataInputStream(
            socket.getInputStream());
        char response = is.readChar();
        System.out.println("Response from the server:" + response);
        System.out.print("You want to continue? (Yes/No):");
      } catch (UnknownHostException e) {
        e.printStackTrace();
      } finally {
        socket.close();
      }
    } while (input.readLine().equalsIgnoreCase("yes"));
  }
}
TOP

Related Classes of ua.SimpleClient

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.