resourcepool / ssdp-client

The most lightweight asynchronous Java SSDP (Simple Service Discovery Protocol) Client
Apache License 2.0
53 stars 21 forks source link

java.net.SocketException: setsockopt failed: EADDRINUSE (Address already in use) #20

Closed jenish-jadav closed 4 years ago

jenish-jadav commented 4 years ago

Error Stack

2020-08-27 16:26:43.122 8155-8155/? W/System.err: java.net.SocketException: setsockopt failed: EADDRINUSE (Address already in use)
2020-08-27 16:26:43.122 8155-8155/? W/System.err:     at libcore.io.IoBridge.setSocketOption(IoBridge.java:367)
2020-08-27 16:26:43.122 8155-8155/? W/System.err:     at java.net.PlainDatagramSocketImpl.join(PlainDatagramSocketImpl.java:184)
2020-08-27 16:26:43.122 8155-8155/? W/System.err:     at java.net.AbstractPlainDatagramSocketImpl.joinGroup(AbstractPlainDatagramSocketImpl.java:221)
2020-08-27 16:26:43.122 8155-8155/? W/System.err:     at java.net.MulticastSocket.joinGroup(MulticastSocket.java:406)
2020-08-27 16:26:43.122 8155-8155/? W/System.err:     at io.resourcepool.ssdp.client.impl.SsdpClientImpl.joinGroupOnAllInterfaces(SsdpClientImpl.java:261)
2020-08-27 16:26:43.123 8155-8155/? W/System.err:     at io.resourcepool.ssdp.client.impl.SsdpClientImpl.openAndBindSocket(SsdpClientImpl.java:189)
2020-08-27 16:26:43.123 8155-8155/? W/System.err:     at io.resourcepool.ssdp.client.impl.SsdpClientImpl.discoverServices(SsdpClientImpl.java:105)
2020-08-27 16:26:43.123 8155-8155/? W/System.err:     at netsol.app.ssdpclient.activity.MainActivity.getList(MainActivity.java:93)
2020-08-27 16:26:43.123 8155-8155/? W/System.err:     at netsol.app.ssdpclient.activity.MainActivity.access$100(MainActivity.java:36)
2020-08-27 16:26:43.123 8155-8155/? W/System.err:     at netsol.app.ssdpclient.activity.MainActivity$1.onChanged(MainActivity.java:73)
2020-08-27 16:26:43.123 8155-8155/? W/System.err:     at netsol.app.ssdpclient.activity.MainActivity$1.onChanged(MainActivity.java:65)
2020-08-27 16:26:43.123 8155-8155/? W/System.err:     at androidx.lifecycle.LiveData.considerNotify(LiveData.java:113)
2020-08-27 16:26:43.123 8155-8155/? W/System.err:     at androidx.lifecycle.LiveData.dispatchingValue(LiveData.java:131)
2020-08-27 16:26:43.123 8155-8155/? W/System.err:     at androidx.lifecycle.LiveData.setValue(LiveData.java:289)
2020-08-27 16:26:43.123 8155-8155/? W/System.err:     at androidx.lifecycle.LiveData$1.run(LiveData.java:91)
2020-08-27 16:26:43.123 8155-8155/? W/System.err:     at android.os.Handler.handleCallback(Handler.java:873)
2020-08-27 16:26:43.123 8155-8155/? W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:99)
2020-08-27 16:26:43.123 8155-8155/? W/System.err:     at android.os.Looper.loop(Looper.java:193)
2020-08-27 16:26:43.123 8155-8155/? W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6669)
2020-08-27 16:26:43.123 8155-8155/? W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
2020-08-27 16:26:43.123 8155-8155/? W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
2020-08-27 16:26:43.123 8155-8155/? W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
2020-08-27 16:26:43.123 8155-8155/? W/System.err: Caused by: android.system.ErrnoException: setsockopt failed: EADDRINUSE (Address already in use)
2020-08-27 16:26:43.123 8155-8155/? W/System.err:     at libcore.io.Linux.setsockoptGroupReq(Native Method)
2020-08-27 16:26:43.123 8155-8155/? W/System.err:     at libcore.io.ForwardingOs.setsockoptGroupReq(ForwardingOs.java:172)
2020-08-27 16:26:43.123 8155-8155/? W/System.err:     at libcore.io.IoBridge.setSocketOptionErrno(IoBridge.java:452)
2020-08-27 16:26:43.123 8155-8155/? W/System.err:     at libcore.io.IoBridge.setSocketOption(IoBridge.java:365)
2020-08-27 16:26:43.123 8155-8155/? W/System.err:   ... 21 more

Code Snippet:


client = SsdpClient.create();
        DiscoveryRequest specificDevice = SsdpRequest.builder()
                .serviceType("urn:schemas-upnp-org:device:basic:1")
                .build();

        client.discoverServices(specificDevice, new DiscoveryListener() {
            @Override
            public void onServiceDiscovered(SsdpService service) {
                fillAdapter(service);
                Messages.log("Found service: " + service);
            }

            @Override
            public void onServiceAnnouncement(SsdpServiceAnnouncement announcement) {
                setMsg("Announcement: " + announcement.getOriginalResponse().toString());
            }

            @Override
            public void onFailed(Exception ex) {
                setMsg("Fail: " + ex.toString());
                ex.printStackTrace();
            }
        });
loicortola commented 4 years ago

Hello,

thanks for the issue. That means you are binding to a port already used on the device. Is your device already listening on the specific port ? You may use a different port using the options.