MultiServerThreadToClients.java 769 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 28 29
package chatRoom;

import java.io.IOException;
import java.util.ArrayList;

public class MultiServerThreadToClients extends Thread {
    private ArrayList<MultiServerThreadFromClient> threads;
    private MultiQueue q;

    public MultiServerThreadToClients(ArrayList<MultiServerThreadFromClient> threads, MultiQueue q) {
        this.threads = threads;
        this.q = q;
    }

    public void run() {
        MultiMessage newMsg;
        while(true) {
            newMsg = q.take();

            for(MultiServerThreadFromClient t: threads) {
                try {
                    t.sendMsg(newMsg);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}