java.net.MulticastSocket#setSoTimeout ( )源码实例Demo

下面列出了java.net.MulticastSocket#setSoTimeout ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netty-4.1.22   文件: OioDatagramChannel.java
/**
 * Create a new instance from the given {@link MulticastSocket}.
 *
 * @param socket    the {@link MulticastSocket} which is used by this instance
 */
public OioDatagramChannel(MulticastSocket socket) {
    super(null);

    boolean success = false;
    try {
        socket.setSoTimeout(SO_TIMEOUT);
        socket.setBroadcast(false);
        success = true;
    } catch (SocketException e) {
        throw new ChannelException(
                "Failed to configure the datagram socket timeout.", e);
    } finally {
        if (!success) {
            socket.close();
        }
    }

    this.socket = socket;
    config = new DefaultOioDatagramChannelConfig(this, socket);
}
 
源代码2 项目: smarthome   文件: CcuDiscoveryService.java
private synchronized void startDiscovery() {
    try {
        logger.debug("Starting Homematic CCU discovery scan");
        String configuredBroadcastAddress = networkAddressService.getConfiguredBroadcastAddress();
        if (configuredBroadcastAddress != null) {
            broadcastAddress = InetAddress.getByName(configuredBroadcastAddress);
        }
        if (broadcastAddress == null) {
            logger.warn("Homematic CCU discovery: discovery not possible, no broadcast address found");
            return;
        }
        socket = new MulticastSocket();
        socket.setBroadcast(true);
        socket.setTimeToLive(5);
        socket.setSoTimeout(800);

        sendBroadcast();
        receiveResponses();
    } catch (Exception ex) {
        logger.error("An error was thrown while running Homematic CCU discovery {}", ex.getMessage(), ex);
    } finally {
        scanFuture = null;
    }
}
 
源代码3 项目: tomee   文件: MulticastDiscoveryAgent.java
Multicast(final Tracker tracker) throws IOException {
    this.tracker = tracker;

    multicast = new MulticastSocket(port);
    multicast.setLoopbackMode(loopbackMode);
    multicast.setTimeToLive(timeToLive);
    multicast.joinGroup(address.getAddress());
    multicast.setSoTimeout((int) heartRate);

    listenerThread = new Thread(new Listener());
    listenerThread.setName("MulticastDiscovery: Listener");
    listenerThread.setDaemon(true);
    listenerThread.start();

    final Broadcaster broadcaster = new Broadcaster();

    timer = new Timer("MulticastDiscovery: Broadcaster", true);
    timer.scheduleAtFixedRate(broadcaster, 0, heartRate);

}
 
源代码4 项目: netty4.0.27Learn   文件: OioDatagramChannel.java
/**
 * Create a new instance from the given {@link MulticastSocket}.
 *
 * @param socket    the {@link MulticastSocket} which is used by this instance
 */
public OioDatagramChannel(MulticastSocket socket) {
    super(null);

    boolean success = false;
    try {
        socket.setSoTimeout(SO_TIMEOUT);
        socket.setBroadcast(false);
        success = true;
    } catch (SocketException e) {
        throw new ChannelException(
                "Failed to configure the datagram socket timeout.", e);
    } finally {
        if (!success) {
            socket.close();
        }
    }

    this.socket = socket;
    config = new DefaultDatagramChannelConfig(this, socket);
}
 
源代码5 项目: openhab1-addons   文件: SsdpDiscovery.java
/**
 * Broadcasts a SSDP discovery message into the network to find provided
 * services.
 * 
 * @return The Socket the answers will arrive at.
 * @throws UnknownHostException
 * @throws IOException
 * @throws SocketException
 * @throws UnsupportedEncodingException
 */
private MulticastSocket sendDiscoveryBroacast()
        throws UnknownHostException, IOException, SocketException, UnsupportedEncodingException {
    InetAddress multicastAddress = InetAddress.getByName("239.255.255.250");
    final int port = 1900;
    MulticastSocket socket = new MulticastSocket(port);
    socket.setReuseAddress(true);
    socket.setSoTimeout(130000);
    socket.joinGroup(multicastAddress);
    byte[] requestMessage = DISCOVER_MESSAGE.getBytes("UTF-8");
    DatagramPacket datagramPacket = new DatagramPacket(requestMessage, requestMessage.length, multicastAddress,
            port);
    socket.send(datagramPacket);
    return socket;
}
 
源代码6 项目: tomee   文件: MulticastSearch.java
public MulticastSearch(final String host, final int port) throws IOException {
    final InetAddress inetAddress = InetAddress.getByName(host);

    multicast = new MulticastSocket(port);
    multicast.joinGroup(inetAddress);
    multicast.setSoTimeout(500);
}
 
源代码7 项目: openvisualtraceroute   文件: UDP.java
private static void test() throws Exception {
	final String hostname = "google.com";
	final String localhost = "localhost";
	final MulticastSocket datagramSocket = new MulticastSocket();
	datagramSocket.setSoTimeout(10000);
	short ttl = 1;
	final InetAddress receiverAddress = InetAddress.getByName(hostname);
	while (ttl < 100) {
		try {
			byte[] buffer = "0123456789".getBytes();
			datagramSocket.setTimeToLive(ttl++);
			final DatagramPacket sendPacket = new DatagramPacket(buffer, buffer.length, receiverAddress, 80);

			datagramSocket.send(sendPacket);

			buffer = new byte[10];
			final DatagramPacket receivePacket = new DatagramPacket(buffer, buffer.length);

			datagramSocket.receive(receivePacket);
			System.out.println("ttl=" + ttl + " address=" + receivePacket.getAddress().getHostAddress() + " data="
					+ new String(receivePacket.getData()));
			Thread.sleep(1000);
		} catch (final SocketTimeoutException e) {
			System.out.println("timeout ttl=" + ttl);
		}
	}
}
 
源代码8 项目: openhab1-addons   文件: SsdpDiscovery.java
/**
 * Scans all messages that arrive on the socket and scans them for the
 * search keywords. The search is not case sensitive.
 * 
 * @param socket
 *            The socket where the answers arrive.
 * @param keywords
 *            The keywords to be searched for.
 * @return
 * @throws IOException
 */
private String scanResposesForKeywords(MulticastSocket socket, String... keywords) throws IOException {
    // In the worst case a SocketTimeoutException raises
    socket.setSoTimeout(2000);
    do {
        logger.debug("Got an answer message.");
        byte[] rxbuf = new byte[8192];
        DatagramPacket packet = new DatagramPacket(rxbuf, rxbuf.length);
        socket.receive(packet);
        String foundIp = analyzePacket(packet, keywords);
        if (foundIp != null) {
            return foundIp;
        }
    } while (true);
}
 
源代码9 项目: Bitcoin   文件: Multicast.java
/**
 * Blocking call
 */
public static boolean recvData(MulticastSocket s, byte[] buffer) throws IOException {
    s.setSoTimeout(100);
    // Create a DatagramPacket and do a receive
    final DatagramPacket pack = new DatagramPacket(buffer, buffer.length);
    try {
        s.receive(pack);
    } catch (SocketTimeoutException e) {
        return false;
    }
    // We have finished receiving data
    return true;
}
 
源代码10 项目: mpegts-streamer   文件: UDPTransport.java
private UDPTransport(String address, int port, int ttl, int soTimeout) throws IOException {
	// InetSocketAddress
	inetSocketAddress = new InetSocketAddress(address, port);

	// Create the socket but we don't bind it as we are only going to send data
	// Note that we don't have to join the multicast group if we are only sending data and not receiving
	multicastSocket = new MulticastSocket();
	multicastSocket.setReuseAddress(true);
	multicastSocket.setSoTimeout(soTimeout);
	multicastSocket.setTimeToLive(ttl);
}
 
源代码11 项目: dragonwell8_jdk   文件: ClientConnection.java
public MulticastSocket connectWithTimeout(int msTimeOut) throws IOException {
    MulticastSocket socket = new MulticastSocket(port);
    socket.joinGroup(address);
    socket.setSoTimeout(msTimeOut);
    return socket;
}
 
源代码12 项目: jdk8u60   文件: ClientConnection.java
public MulticastSocket connectWithTimeout(int msTimeOut) throws IOException {
    MulticastSocket socket = new MulticastSocket(port);
    socket.joinGroup(address);
    socket.setSoTimeout(msTimeOut);
    return socket;
}
 
源代码13 项目: openjdk-jdk8u-backup   文件: ClientConnection.java
public MulticastSocket connectWithTimeout(int msTimeOut) throws IOException {
    MulticastSocket socket = new MulticastSocket(port);
    socket.joinGroup(address);
    socket.setSoTimeout(msTimeOut);
    return socket;
}
 
源代码14 项目: openjdk-jdk9   文件: ClientConnection.java
public MulticastSocket connectWithTimeout(int msTimeOut) throws IOException {
    MulticastSocket socket = new MulticastSocket(port);
    socket.joinGroup(address);
    socket.setSoTimeout(msTimeOut);
    return socket;
}
 
源代码15 项目: hottub   文件: ClientConnection.java
public MulticastSocket connectWithTimeout(int msTimeOut) throws IOException {
    MulticastSocket socket = new MulticastSocket(port);
    socket.joinGroup(address);
    socket.setSoTimeout(msTimeOut);
    return socket;
}
 
源代码16 项目: openjdk-8-source   文件: ClientConnection.java
public MulticastSocket connectWithTimeout(int msTimeOut) throws IOException {
    MulticastSocket socket = new MulticastSocket(port);
    socket.joinGroup(address);
    socket.setSoTimeout(msTimeOut);
    return socket;
}
 
源代码17 项目: openjdk-8   文件: ClientConnection.java
public MulticastSocket connectWithTimeout(int msTimeOut) throws IOException {
    MulticastSocket socket = new MulticastSocket(port);
    socket.joinGroup(address);
    socket.setSoTimeout(msTimeOut);
    return socket;
}
 
源代码18 项目: jdk8u_jdk   文件: ClientConnection.java
public MulticastSocket connectWithTimeout(int msTimeOut) throws IOException {
    MulticastSocket socket = new MulticastSocket(port);
    socket.joinGroup(address);
    socket.setSoTimeout(msTimeOut);
    return socket;
}
 
源代码19 项目: jdk8u-jdk   文件: ClientConnection.java
public MulticastSocket connectWithTimeout(int msTimeOut) throws IOException {
    MulticastSocket socket = new MulticastSocket(port);
    socket.joinGroup(address);
    socket.setSoTimeout(msTimeOut);
    return socket;
}
 
源代码20 项目: jdk8u-dev-jdk   文件: ClientConnection.java
public MulticastSocket connectWithTimeout(int msTimeOut) throws IOException {
    MulticastSocket socket = new MulticastSocket(port);
    socket.joinGroup(address);
    socket.setSoTimeout(msTimeOut);
    return socket;
}