import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;

public class ClientTCP {
	public static void main(String args[]) throws Exception {

		System.out.println("Please enter the address of the server (port is set to TCP/6017) :");
		Scanner scanner = new Scanner(System.in);
		String serveraddress = scanner.nextLine();

		// Create a client socket and connect to given address on TCP/6017
		Socket sc = new Socket(serveraddress, 6017);

		// Build a BufferedReader to read text from socket
		BufferedReader entreeSocket = new BufferedReader(new InputStreamReader(sc.getInputStream()));

		// Build a PrintStream to send text on socket
		PrintStream sortieSocket = new PrintStream(sc.getOutputStream());

		//string to verify if it's the correct application asking qotd
		String checkapp = "qotd";

		// sending string on socket
		sortieSocket.println(checkapp);

		// read the string from socket
		String qotdserv = entreeSocket.readLine();
		System.out.println(qotdserv);

		// close connection
		sc.close();
	}
}
