Android Question ServerSocket and Port

Firpas

Active Member
Licensed User
Longtime User
Hi to everybody:

I'm Trying to initialize a ServerSocket

B4X:
Sub Process_Globals
...
Private SvrSocket1 As ServerSocket
...

Sub Service_Create
   
    SvrSocket1.Initialize(2025, "SvrSocket1")

but ....
How do I can know if the port is in use by another application or service?

Thanks in advance
 

giga

Well-Known Member
Licensed User
Longtime User
I think this one may be hard as applications/services can use many different ports, based on how the are written. If the said application/service is not running at the time you "checked" the port you would not know that is the one it uses.

Ports open and close so catching them may be the biggest challenge.
 
Upvote 0

Firpas

Active Member
Licensed User
Longtime User
Hi

Thanks for yours replay.

I had resolved with the following code:

B4X:
        Dim MyPort as int = 2020
        Dim Sw As Boolean = False
        Do While Sw = False
            Try
                SvrSocket1.Initialize(MyPort, "SvrSocket1")
                Sw = True
            Catch
                MyPort = MyPort + 1
            End Try
        Loop

Thanks
 
Upvote 0
Top