FAQ
I want to write a test program to test web server which register a free
port.

But, when we Listening, we must provide a parameter e.g :6060.

Because port 6060 is occupied by godoc sometimes, I wish my server_test.go
will run as soon as possible.
So, I require to assign a free port number.

Any suggestion?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Tamás Gulácsi at May 14, 2013 at 9:11 am
    Use 0 as port number.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jim Teeuwen at May 14, 2013 at 9:12 am
    Use Port 0. The operating system will then assign you a free one
    automatically.
    You can see which one was chosen through Listener.Address(), after it has
    opened.
    On Tuesday, May 14, 2013 9:53:44 AM UTC+2, dlin wrote:

    I want to write a test program to test web server which register a free
    port.

    But, when we Listening, we must provide a parameter e.g :6060.

    Because port 6060 is occupied by godoc sometimes, I wish my
    server_test.go will run as soon as possible.
    So, I require to assign a free port number.

    Any suggestion?
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Dlin at May 14, 2013 at 9:29 am
    Thank you,
    In fact,
    In my test, not only the web server required a free port.

    I required multiple clients assigned by local port number.
    Is there API to get the free local port number for the clients to use?

    At the first test, the test will pass.
    At 2nd test, the client dialer Dial() to server will caused 'address
    already used' error.
    And use 'netstat -tan | grep <port>' will see it is on TIME_WAIT state.
    So, I think to let the auto test smooth is to get a free local port at
    first.
    On Tuesday, May 14, 2013 5:12:22 PM UTC+8, Jim Teeuwen wrote:

    Use Port 0. The operating system will then assign you a free one
    automatically.
    You can see which one was chosen through Listener.Address(), after it has
    opened.
    On Tuesday, May 14, 2013 9:53:44 AM UTC+2, dlin wrote:

    I want to write a test program to test web server which register a free
    port.

    But, when we Listening, we must provide a parameter e.g :6060.

    Because port 6060 is occupied by godoc sometimes, I wish my
    server_test.go will run as soon as possible.
    So, I require to assign a free port number.

    Any suggestion?
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Lu dongping at May 14, 2013 at 9:50 am
    l,_ := net.Listen("tcp",":0")
    defer l.Close()
    println(l.Addr().String())




    On Tue, May 14, 2013 at 3:53 PM, dlin wrote:

    I want to write a test program to test web server which register a free
    port.

    But, when we Listening, we must provide a parameter e.g :6060.

    Because port 6060 is occupied by godoc sometimes, I wish my
    server_test.go will run as soon as possible.
    So, I require to assign a free port number.

    Any suggestion?

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Dlin at May 14, 2013 at 11:05 am
    Thanks, I just use "" empty string. And it works.

    On Tuesday, May 14, 2013 5:50:50 PM UTC+8, outersky wrote:

    l,_ := net.Listen("tcp",":0")
    defer l.Close()
    println(l.Addr().String())





    On Tue, May 14, 2013 at 3:53 PM, dlin <dli...@gmail.com <javascript:>>wrote:
    I want to write a test program to test web server which register a free
    port.

    But, when we Listening, we must provide a parameter e.g :6060.

    Because port 6060 is occupied by godoc sometimes, I wish my
    server_test.go will run as soon as possible.
    So, I require to assign a free port number.

    Any suggestion?

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/groups/opt_out.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMay 14, '13 at 7:53a
activeMay 14, '13 at 11:05a
posts6
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase