Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Lab9;
- import java.io.*;
- import java.net.*;
- public class EchoClient {
- public static void main(String[] args) throws IOException {
- Socket echoSocket = null;
- PrintWriter out = null;
- BufferedReader in = null;
- try {
- //149.156.207.21
- echoSocket = new Socket("localhost", 6666);
- out = new PrintWriter(echoSocket.getOutputStream(), true);
- in = new BufferedReader(new InputStreamReader(
- echoSocket.getInputStream()));
- } catch (UnknownHostException e) {
- System.err.println("Don't know about host: localhost.");
- System.exit(1);
- } catch (IOException e) {
- System.err.println("Couldn't get I/O for "
- + "the connection to: localhost.");
- System.exit(1);
- }
- BufferedReader stdIn = new BufferedReader(
- new InputStreamReader(System.in));
- String userInput;
- System.out.println("Type a message: ");
- while ((userInput = stdIn.readLine()) != null) {
- out.println(userInput);
- System.out.println("echo: " + in.readLine());
- }
- out.close();
- in.close();
- stdIn.close();
- echoSocket.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement