Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.net.BindException: Cannot assign requested address #693

Open
Smartelic opened this issue Feb 7, 2021 · 0 comments
Open

java.net.BindException: Cannot assign requested address #693

Smartelic opened this issue Feb 7, 2021 · 0 comments

Comments

@Smartelic
Copy link

Smartelic commented Feb 7, 2021

AsyncServer.getDefault().listen(host, port, new ListenCallback() is giving bind exception all the time.

Here is the crash log,

--------- beginning of crash
2021-02-07 02:03:05.832 11083-11134/com.github.renewb.androidasyncsocketexamples E/AndroidRuntime: FATAL EXCEPTION: AsyncServer
  Process: com.github.renewb.androidasyncsocketexamples, PID: 11083
  java.lang.RuntimeException: java.net.BindException: Cannot assign requested address
      at com.github.reneweb.androidasyncsocketexamples.tcp.Server$1.onCompleted(Server.java:47)
      at com.koushikdutta.async.AsyncServer$3.run(AsyncServer.java:368)
      at com.koushikdutta.async.AsyncServer.lambda$run$1(AsyncServer.java:210)
      at com.koushikdutta.async.-$$Lambda$AsyncServer$Wv_yQXhLxsNsbvajGAFlXa0mU2Y.run(Unknown Source:4)
      at com.koushikdutta.async.AsyncServer$Scheduled.run(AsyncServer.java:236)
      at com.koushikdutta.async.AsyncServer.lockAndRunQueue(AsyncServer.java:788)
      at com.koushikdutta.async.AsyncServer.runLoop(AsyncServer.java:806)
      at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:717)
      at com.koushikdutta.async.AsyncServer.access$800(AsyncServer.java:46)
      at com.koushikdutta.async.AsyncServer$11.run(AsyncServer.java:671)
   Caused by: java.net.BindException: Cannot assign requested address
      at sun.nio.ch.Net.bind0(Native Method)
      at sun.nio.ch.Net.bind(Net.java:442)
      at sun.nio.ch.Net.bind(Net.java:434)
      at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
      at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
      at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:67)

It's working fine, when i tried with val socket = Socket(serverAddress, PORT) .

Here is the code snippet that i am using

AsyncServer.getDefault().listen(host, port, new ListenCallback() {

           @Override
           public void onAccepted(final AsyncSocket socket) {
               handleAccept(socket);
           }

           @Override
           public void onListening(AsyncServerSocket socket) {
               System.out.println("[Server] Server started listening for connections");
           }

           @Override
           public void onCompleted(Exception ex) {
               if(ex != null) throw new RuntimeException(ex);
               System.out.println("[Server] Successfully shutdown server");
           }
       });

Is there anything i am missing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant