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

chuck3e

Active Member
Licensed User
Longtime 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
 

chuck3e

Active Member
Licensed User
Longtime User
Do you know which app is using this port?
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.
 
Upvote 0

chuck3e

Active Member
Licensed User
Longtime 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.
 
Upvote 0

chuck3e

Active Member
Licensed User
Longtime 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
 
Upvote 0

chuck3e

Active Member
Licensed User
Longtime 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.
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?
 
Upvote 0

chuck3e

Active Member
Licensed User
Longtime 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.
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
 
Upvote 0
Top