Client.java 814 Bytes
Newer Older
Michele Fiori's avatar
Michele Fiori committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
package chatRoom;

import java.io.*;
import java.net.*;

class Client {
    public static void main(String argv[]) throws Exception {
        Queue q = new Queue();

        // Thread that reads messages from stdin end queues them
        KeyboardThread kt = new KeyboardThread(q);
        kt.start();


        Socket clientSocket = new Socket("localhost", 6789);

        // Thread that reads the message from a client and queues it to be forwarded to other clients
        ToOtherUserThread ous = new ToOtherUserThread(clientSocket, q);
        ous.start();

        BufferedReader inFromServer =
                new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
        while(true) {
            System.out.println(inFromServer.readLine());
        }
    }
}