All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.antmedia.ipcamera.onvifdiscovery.ProbeSenderThread Maven / Gradle / Ivy

Go to download

Ant Media Server supports RTMP, RTSP, MP4, HLS, WebRTC, Adaptive Streaming, etc.

There is a newer version: 2.10.0
Show newest version
package io.antmedia.ipcamera.onvifdiscovery;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class ProbeSenderThread extends Thread {
	
	private Thread probeReceiverThread;
	private DatagramSocket socket;
	private CountDownLatch serverStarted;
	private CountDownLatch serverFinished;
	private InetAddress address;
	private String probeMsgTemplate;

	public ProbeSenderThread(InetAddress address, DatagramSocket socket, String probeMsgTemplate,
			CountDownLatch serverStarted, CountDownLatch serverFinished, Thread probeReceiverThread) {
		this.probeReceiverThread = probeReceiverThread;
		this.serverStarted = serverStarted;
		this.serverFinished = serverFinished;
		this.socket = socket;
		this.address = address;
		this.probeMsgTemplate = probeMsgTemplate;
	}

	public void run() {
		try {
			final String uuid = UUID.randomUUID().toString();
			final String probe = probeMsgTemplate.replaceAll(
					"urn:uuid:.*",
					"urn:uuid:" + uuid + "");
			probeReceiverThread.start();
			try {
				serverStarted.await(1000, TimeUnit.MILLISECONDS);
			} catch (InterruptedException e) {
				e.printStackTrace();
				Thread.currentThread().interrupt();
			}
			socket.send(new DatagramPacket(probe.getBytes(), probe.length(), address, DeviceDiscovery.WS_DISCOVERY_PORT));
		} catch (Exception e) {
			e.printStackTrace();
		}
		try {
			serverFinished.await(DeviceDiscovery.WS_DISCOVERY_TIMEOUT, TimeUnit.MILLISECONDS);
		} catch (InterruptedException e) {
			e.printStackTrace();
			Thread.currentThread().interrupt();
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy