
package network;

import java.io.*;
import java.net.*;


public class SenderThread extends Thread {

    DatagramSocket socket = null;
    BufferQueue sendBuffer = null;

    boolean stopThread = false;


    public SenderThread(DatagramSocket s, BufferQueue buffer) {
        socket = s;
        sendBuffer = buffer;
    }

    public void requestStop() {
        stopThread = true;
    }

    public void run() {
        DatagramPacket packet = null;

        while (!stopThread) {
            try {
                packet = sendBuffer.dequeue();
                socket.send(packet);
                //System.out.println("Packet sent");
            }
            catch (IOException e) {

            }
            catch (InterruptedException e) {

            }
        }
    }
}