Android Question bind failed: EADDRINUSE (Address already in use)

Discussion in 'Android Questions' started by chuck3e, Nov 17, 2014.

  1. chuck3e

    chuck3e Active Member Licensed User

    I want to be able to prevent the following error if the user doesn't exit the app properly:

    "Caused by: libcore.io.ErrnoException: bind failed: EADDRINUSE (Address already in use)".

    It appears to fail on server.Initialize(port, "server") in the service module of the new app. I added a server.close before this command but it didn't fix it. Is there another command I need to use?

    What is the proper procedure for closing this if another app on the same tablet didn't terminate properly? For example: If an app is started then "back buttoned" out of, and the user forgets about it, and then starts up a different app on the same tablet that tries to wifi connect.

    -Chuck
     
  2. Fusseldieb

    Fusseldieb Active Member Licensed User

  3. Erel

    Erel Administrator Staff Member Licensed User

    Do you know which app is using this port?
     
  4. chuck3e

    chuck3e Active Member Licensed User

    Erel. they both are. I have a file-send app and a file-recieve app.

    For example: If the user sends a file to another tablet and then forgets the send-app is still active on his tablet, then wants to receive a file, the receive-app will fail. The reverse is true also. He receives, leaves the receive app running and tries to run the send-app it will also fail on the "already in use" error. I don't want the user to have to kill each app before running the other if I can avoid it.
     
  5. chuck3e

    chuck3e Active Member Licensed User

    Erel.
    I'm not sure I answered your question about the port. The port is defined as "Private port As Int = 21341" and both apps are using the same number.
     
  6. chuck3e

    chuck3e Active Member Licensed User

    Fusseldieb, Thank you for your suggestion. I looked at the code in your link and tried to implement it but I don't yet know enough about those commands to know how to implement them in B4a. It seems the more I learn, the more I have to learn. :)
    -Chuck
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    The app that is sending the file doesn't need to open this port for incoming connections. Only the app that is receiving the file should lock this port.
     
  8. chuck3e

    chuck3e Active Member Licensed User

    Erel, thanks for your reply. I tried some things to implement your suggestion but am sorely lacking in know-how. Can you direct me to the command that is doing the port locking?
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    The port is locked when you call ServerSocket.Initialize. The app that sends the data doesn't need to use a ServerSocket at all.
     
    chuck3e likes this.
  10. chuck3e

    chuck3e Active Member Licensed User

    Erel, Thank you very much!! That fixed my problem! It was coded at the start of the service module example because that example is doing dual purpose send/receive. With your help I got it figured out now.
    -Chuck
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice