2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.mihome.internal.socket;
15 import java.io.IOException;
16 import java.net.InetAddress;
17 import java.net.MulticastSocket;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * Takes care of the multicast communication with the bridge.
26 * @author Dieter Schmidt - Initial contribution
30 public class XiaomiBridgeSocket extends XiaomiSocket {
32 private final Logger logger = LoggerFactory.getLogger(XiaomiBridgeSocket.class);
34 public XiaomiBridgeSocket(int port, String owner) {
39 * Sets up the {@link XiaomiBridgeSocket}.
41 * Connects the socket to the specific multicast address and port.
44 protected synchronized void setupSocket() {
45 MulticastSocket socket = (MulticastSocket) getSocket();
47 logger.debug("Socket already setup");
52 logger.debug("Setup socket");
53 socket = new MulticastSocket(getPort());
54 setSocket(socket); // must bind receive side
55 socket.joinGroup(InetAddress.getByName(MCAST_ADDR));
56 logger.debug("Initialized socket to {}:{} on {}:{}", socket.getRemoteSocketAddress(), socket.getPort(),
57 socket.getLocalAddress(), socket.getLocalPort());
58 } catch (IOException e) {
59 logger.error("Setup socket error", e);