001package ball.upnp.ssdp;
002/*-
003 * ##########################################################################
004 * UPnP/SSDP Implementation Classes
005 * %%
006 * Copyright (C) 2013 - 2022 Allen D. Ball
007 * %%
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *      http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 * ##########################################################################
020 */
021import java.io.IOException;
022import java.net.InetSocketAddress;
023import java.net.MulticastSocket;
024import lombok.ToString;
025
026/**
027 * SSDP discovery {@link MulticastSocket} implementation.
028 *
029 * {@bean.info}
030 *
031 * @author {@link.uri mailto:ball@hcf.dev Allen D. Ball}
032 */
033@ToString
034public class SSDPMulticastSocket extends MulticastSocket {
035    private static final String ADDRESS = "239.255.255.250";
036    private static final int PORT = 1900;
037
038    /**
039     * SSDP IPv4 multicast {@link InetSocketAddress}.
040     */
041    public static final InetSocketAddress INET_SOCKET_ADDRESS = new InetSocketAddress(ADDRESS, PORT);
042
043    /**
044     * Sole constructor.
045     */
046    public SSDPMulticastSocket() throws IOException {
047        super(PORT);
048
049        setReuseAddress(true);
050        setLoopbackMode(false);
051        setTimeToLive(2);
052        joinGroup(INET_SOCKET_ADDRESS.getAddress());
053    }
054}