Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.*;
- public class EmployeeClient {
- private static final String HOST = "localhost";
- private static final int PORT = 8080;
- public static void main(String[] args) {
- try (Socket socket = new Socket(HOST, PORT)) {
- InputStream input = socket.getInputStream();
- BufferedReader reader = new BufferedReader(new InputStreamReader(input));
- OutputStream output = socket.getOutputStream();
- PrintWriter writer = new PrintWriter(output, true);
- BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in));
- String text;
- System.out.println("Enter employee ID (or 'exit' to quit):");
- while ((text = consoleReader.readLine()) != null) {
- writer.println(text);
- if (text.equals("exit")) {
- break;
- }
- String response = reader.readLine();
- System.out.println("Server response: " + response);
- }
- socket.close();
- } catch (UnknownHostException ex) {
- System.out.println("Server not found: " + ex.getMessage());
- } catch (IOException ex) {
- System.out.println("I/O error: " + ex.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement