locked
How to get available TCP port

    Question

  • In  the server, I use StreamSocketListener's BindServiceNameAsync() to bind the port, but i don't know which port is available.

    How can i get an available port ?

    mStreamSocketListener.BindServiceNameAsync("123");



    • Edited by oneonce Saturday, March 28, 2015 1:46 PM
    Saturday, March 28, 2015 1:35 PM

Answers

  • oneonce,

    If you do not specify a port (pass String.Empty or "") the os will choose a port for you.

    This answer you question how to find a port.

    Next problem will be : how to advertise this os-chosen port to the client...

    • Marked as answer by oneonce Tuesday, March 31, 2015 3:32 PM
    Monday, March 30, 2015 7:43 PM

All replies

  • Hi oneonce,

    Is that means you would like to know if "123" port is available on current OS programmatically by Windows Store App?

    Base on my understanding, Windows Store App runs in a sandbox mode to ensure safety, we do not have any permission to know if system have the Tcp port open, meanwhile TcpConnectionInformation Class does not supported in Windows Store App.

    The answer for this question is we do not have any way to detect that.

    However I'm not sure why you ask such question, let's say if we know that "123" port is not available in local machine, will you change to another TCP port?

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 30, 2015 5:54 AM
    Moderator
  • Hi Jamles

       Thanks for your reply.

       Yes, I want to know "123" port whether is available.

       If the "123" port is not available, it will be a troublesome thing, I have some Clients connect to the it. I can try others port, but it is not a good way.

       If StreamSocketListenert can bind a string, the system can map the string to an available  port automatically,  it w'll be nice.


    • Edited by oneonce Monday, March 30, 2015 12:47 PM
    Monday, March 30, 2015 12:46 PM
  • oneonce,

    If you do not specify a port (pass String.Empty or "") the os will choose a port for you.

    This answer you question how to find a port.

    Next problem will be : how to advertise this os-chosen port to the client...

    • Marked as answer by oneonce Tuesday, March 31, 2015 3:32 PM
    Monday, March 30, 2015 7:43 PM
  • oneonce,

    If you do not specify a port (pass String.Empty or "") the os will choose a port for you.

    This answer you question how to find a port.

    Next problem will be : how to advertise this os-chosen port to the client...

    hi cuneyiit

        Thank you,

        I'll try String.Empty and "", if os choose a port for me, i can get it via StreamSocketListener, then i'll show it on UI, the client input it.

    Tuesday, March 31, 2015 1:14 AM