package bt;

import java.io.DataOutputStream;

/**
 * Sender线程发送数据类型标志和数据到蓝牙连接
 * 
 * @author DZF
 * @version 1.0.0
 * 
 */
public class Sender implements Runnable {

	public EndPoint endpt;

	private boolean done = false;

	public Sender() {

	}

	public void stop() {
		done = true;
	}

	public void run() {
		// TODO Auto-generated method stub
		try {
			DataOutputStream dataout = endpt.con.openDataOutputStream();
			while (!done) {
				if (!endpt.peekString()) {
					synchronized (this) {
						this.wait(5000);
					}
				}

				MsgPacket m = endpt.getString();

				if (m != null) {
					byte[] infomation = m.getInfomationMsg();
					dataout.write(infomation);
					dataout.flush();
					if (m.type == NetLayer.SIGNAL_TERMINATE) {
						stop();
					}
				}
			}
			dataout.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
