Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A AndroidAsync
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 333
    • Issues 333
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 19
    • Merge requests 19
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Koushik Dutta
  • AndroidAsync
  • Issues
  • #693
Closed
Open
Issue created Feb 07, 2021 by Smartelic@Smartelic

java.net.BindException: Cannot assign requested address

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?

Assignee
Assign to
Time tracking