Android Question ServerSocket and Port

Discussion in 'Android Questions' started by Firpas, Feb 10, 2015.

  1. Firpas

    Firpas Active Member Licensed User

    Hi to everybody:

    I'm Trying to initialize a ServerSocket

    Sub Process_Globals
    Private SvrSocket1 As ServerSocket

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

    Thanks in advance
  2. giga

    giga Well-Known Member Licensed 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.
  3. Erel

    Erel Administrator Staff Member Licensed User

    You can add a Try / Catch block. If it fails switch to an alternative port. The problem is that you will need to also switch to the alternative port in the client.

    This is how the designer works for example. The IDE tries to connect to one port and if it fails it tries to connect to the second port.
  4. Firpas

    Firpas Active Member Licensed User


    Thanks for yours replay.

    I had resolved with the following code:

    Dim MyPort as int = 2020
    Dim Sw As Boolean = False
    Do While Sw = False
                    Sw = 
                    MyPort = MyPort + 
    End Try
    boy8199 likes this.
  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