Specifying ports when creating sockets?

Discussion in 'Ruby' started by Alex Maccaw, Jun 5, 2009.

  1. Alex Maccaw

    Alex Maccaw Guest

    In TCP, when you create a socket to a particular address, the OS chooses
    a free port number.

    I'd like to either specify that port number, or find out that port
    number.

    I can easily find the port number like so:
    socket.addr[1]

    However, that fails when the IO stream is closed. I need to find out the
    port number even if the connection is never made. I'm not sure this is
    possible, which is why I think the first approach, specifying the port
    number, is the way to go.

    If you're wondering why I'm doing this, it's to do with STUNT.

    Can anybody provide any pointers?
    --
    Posted via http://www.ruby-forum.com/.
     
    Alex Maccaw, Jun 5, 2009
    #1
    1. Advertising

  2. Alex Maccaw

    Alex Maccaw Guest

    Alex Maccaw wrote:
    >
    > In TCP, when you create a socket to a particular address, the OS chooses
    > a free port number.
    >
    > I'd like to either specify that port number, or find out that port
    > number.
    >
    > I can easily find the port number like so:
    > socket.addr[1]
    >
    > However, that fails when the IO stream is closed. I need to find out the
    > port number even if the connection is never made. I'm not sure this is
    > possible, which is why I think the first approach, specifying the port
    > number, is the way to go.
    >
    > If you're wondering why I'm doing this, it's to do with STUNT.
    >
    > Can anybody provide any pointers?


    Ok, somebody has kindly let me know that TCPSocket takes 4 options,
    including a local port - oops!

    That should solve the issue.
    --
    Posted via http://www.ruby-forum.com/.
     
    Alex Maccaw, Jun 5, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Kipp
    Replies:
    1
    Views:
    1,208
    Jim Gibson
    Feb 12, 2004
  2. Thomas Kuhn
    Replies:
    4
    Views:
    946
    Thomas Kuhn
    Jul 7, 2003
  3. Replies:
    5
    Views:
    412
    Ghost
    May 11, 2005
  4. cos
    Replies:
    0
    Views:
    499
  5. mreister
    Replies:
    1
    Views:
    3,318
    mreister
    May 25, 2010
Loading...

Share This Page