package chatingApplication;

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.util.Scanner;

public class ClientSide {
	ClientSide() {
		try {
			Socket socket = new Socket("localhost", 2000);
			DataInputStream din = new DataInputStream(socket.getInputStream());
			DataOutputStream dout = new DataOutputStream(socket.getOutputStream());
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String message_in = "", message_out = "";
			System.out.println("\t\t------Client-----");
			System.out.println();
			while (true) {
				
				System.out.print("Message to send:");
				message_out = br.readLine();
				System.out.println();
				if (message_out.equals("bye")) {
					dout.writeUTF("client is offline");
					break;
				}
				dout.writeUTF(message_out);
				message_in = din.readUTF();
				System.out.println("Message received:" + message_in);
				System.out.println();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		new ClientSide();

	}

}
