4thline / cling

UPnP/DLNA library for Java and Android

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Impossible to initialize MulticastReceiverImpl. Port 1900 already in Use

JasonMahdjoub opened this issue · comments

Hi,

I use Cling in order to detect the local router of the lan, and to tell it to open a port with the current computer. I have made some tests, and they work under Linux and under Windows. However, I can't do these tests under MacOS. Here the log of Cling :

org.fourthline.cling.UpnpServiceImpl INFOS : >>> Starting UPnP service...
org.fourthline.cling.UpnpServiceImpl INFOS : Using configuration: com.distrimind.madkit.kernel.network.DefaultUpnpServiceConfiguration
org.fourthline.cling.transport.Router INFOS : Creating Router: org.fourthline.cling.transport.RouterImpl
org.fourthline.cling.transport.spi.MulticastReceiver INFOS : Creating wildcard socket (for receiving multicast datagrams) on port: 1900
org.fourthline.cling.transport.Router GRAVE : Unable to initialize network router: org.fourthline.cling.transport.spi.InitializationException: Could not initialize MulticastReceiverImpl: java.net.BindException: Address already in use
org.fourthline.cling.transport.Router GRAVE : Cause: org.fourthline.cling.transport.spi.InitializationException: Could not initialize MulticastReceiverImpl: java.net.BindException: Address already in use
org.fourthline.cling.UpnpServiceImpl INFOS : <<< UPnP service started successfully

It appears that the port 1900 is officially used by "Back to my mac" on mac OS. But if I make a netstat ou a lsof, no port is opened.

I have also tried to open the upnp service as next, with another port, but a got the same log telling me that the port 1900 is already in use :
upnpService = new UpnpServiceImpl(new DefaultUpnpServiceConfiguration(1902));

Is there some who can help in this situation ?

Thanks in advance,
Jason.

Dlna use SSDP to discovery service. And Cling need to listen on 1900.

https://en.wikipedia.org/wiki/Simple_Service_Discovery_Protocol
SSDP is a text-based protocol based on HTTPU. It uses UDP as the underlying transport protocol. Services are announced by the hosting system with multicast addressing to a specifically designated IP multicast address at UDP port number 1900.

So I have overrited functions of class DefaultUpnpServiceConfiguration, in order to open another port than 1900. Than my tests for discovering local routers work.

@JazZ51,

The port you overrided in DefaultUpnpServiceConfiguration is used for http server, not for ssdp.

public StreamServer createStreamServer(NetworkAddressFactory networkAddressFactory) {
    return new StreamServerImpl(
            new StreamServerConfigurationImpl(
                    networkAddressFactory.getStreamListenPort()
            )
    );
}

Thank you. I am not expert with Cling, but the port I overrided enabled me to make UPNP IGD working into macOS. Ohterwise, macOS refuse binding port 1900 that one service of cling try to open. And then, Cling seems not being able to continue to open UPNP IGD service.