package hh.dejsem.net;

import android.os.Handler;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;

import java.net.SocketException;
import java.net.UnknownHostException;

import hh.lib.D;

public class SendPeerHostThread extends Thread {
	D d;
	Handler abendHandler;
	String ipPort = "";
	Exception exception = null;
	NetUDP netUDP;

	public SendPeerHostThread(D d, Handler abendHandler, String ipPort) throws SocketException, UnknownHostException {
		this.d = d.klon(this);
		this.abendHandler = abendHandler;
		this.ipPort = ipPort;
		netUDP = new NetUDP(d);
	}

	public void run() {
		try { netUDP.keepSendingPeerIp(ipPort); }
		catch(Exception e) {
			try { new Messenger(abendHandler).send(Message.obtain(null, 0, e.getMessage())); }
			catch(RemoteException r) {}
		}
	}

	public void stopAdv() { netUDP.go = false; }
}
