Android Question Server - Detect if port is in use

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I am using a web server in my app and trying to work out if there is a way to detect if the port is already being used.

B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private server As HttpServer
End Sub

Sub StartServer
Dim port As Int = 5555
server.Initialize("Server")
server.Start(port)
End Sub

Is there a way to detect if the port is already in use before the server starts ?
 

aaronk

Well-Known Member
Licensed User
Longtime User
I guess that is one way in doing it. I was using the try..catch but still wondering if there was some other function in doing it.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
I think the only way to know for sure is to catch the exception that's generated if the port is already in use.

- Colin.
 
Upvote 0
Top