socket question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Philippe C. Martin

    #1

    socket question

    Hi,

    I am following a few tutorial and this howto:


    *************** *************** *************** *************** *
    ............
    What happens in the web server is a bit more complex. First, the web
    server creates a "server socket".

    #create an INET, STREAMing socket
    serversocket = socket.socket(
    socket.AF_INET, socket.SOCK_STR EAM)
    #bind the socket to a public host,
    # and a well-known port
    serversocket.bi nd((socket.geth ostname(), 80))
    #become a server socket
    serversocket.li sten(5)

    A couple things to notice: we used socket.gethostn ame() so that the
    socket would be visible to the outside world. If we had used s.bind(('',
    80)) or s.bind(('localh ost', 80)) or s.bind(('127.0. 0.1', 80)) we would
    still have a "server" socket, but one that was only visible within the
    same machine.
    ............
    *************** *************** *************** *************** *

    My problem is that I cannot connect to my server if the client is not on
    the same PC (although I'm doing the above).
    Also:
    1) my server has more than one IP addresses
    2) my server does not have any DNS name


    .... so I want to connect to an IP address that I can ping but has no
    name.


    How can I do that ?

    Regards,

    Philippe
















    --
    *************** ************
    Philippe C. Martin
    SnakeCard LLC
    Secure the right domain name for your business or website today. Custom tailored payment plans available to fit any budget.

    *************** ************

  • Diez B. Roggisch

    #2
    Re: socket question

    > A couple things to notice: we used socket.gethostn ame() so that the[color=blue]
    > socket would be visible to the outside world. If we had used s.bind(('',
    > 80)) or s.bind(('localh ost', 80)) or s.bind(('127.0. 0.1', 80)) we would
    > still have a "server" socket, but one that was only visible within the
    > same machine.[/color]

    This is wrong. There is a difference between passing '' and 'localhost'. The
    latter binds the socket only to the ip 127.0.0.1, where '' binds it to all
    available ips.
    [color=blue]
    > My problem is that I cannot connect to my server if the client is not on
    > the same PC (although I'm doing the above).
    > Also:
    > 1) my server has more than one IP addresses
    > 2) my server does not have any DNS name
    > ... so I want to connect to an IP address that I can ping but has no
    > name.
    > How can I do that ?[/color]

    Pass the ip as hostname (as string like "192.168.1. 10")

    --
    Regards,

    Diez B. Roggisch

    Comment

    • Philippe C. Martin

      #3
      Re: socket question

      Thanks you! that did it.

      PS: the 'wrong' info I got seems to be in the official howtos


      Regards,

      Philippe





      On Mon, 07 Feb 2005 18:23:28 +0100, Diez B. Roggisch wrote:
      [color=blue][color=green]
      >> A couple things to notice: we used socket.gethostn ame() so that the
      >> socket would be visible to the outside world. If we had used s.bind(('',
      >> 80)) or s.bind(('localh ost', 80)) or s.bind(('127.0. 0.1', 80)) we would
      >> still have a "server" socket, but one that was only visible within the
      >> same machine.[/color]
      >
      > This is wrong. There is a difference between passing '' and 'localhost'. The
      > latter binds the socket only to the ip 127.0.0.1, where '' binds it to all
      > available ips.
      >[color=green]
      >> My problem is that I cannot connect to my server if the client is not on
      >> the same PC (although I'm doing the above).
      >> Also:
      >> 1) my server has more than one IP addresses
      >> 2) my server does not have any DNS name
      >> ... so I want to connect to an IP address that I can ping but has no
      >> name.
      >> How can I do that ?[/color]
      >
      > Pass the ip as hostname (as string like "192.168.1. 10")[/color]

      Comment

      • Kartic

        #4
        Re: socket question


        Philippe C. Martin wrote:[color=blue][color=green][color=darkred]
        > >> My problem is that I cannot connect to my server if the client is[/color][/color][/color]
        not on[color=blue][color=green][color=darkred]
        > >> the same PC (although I'm doing the above).[/color][/color][/color]


        Does the machine running the server code also have a firewall installed
        that blocks access to the server port from outside? That is the only
        possibility I can think of that prevents a non-local client from
        connecting.

        Also, please do a netstat -a on the machine running the server and see
        the IP addresses to which the listening port is bound.

        Thanks,
        -Kartic

        Comment

        • Steve Horsley

          #5
          Re: socket question

          Philippe C. Martin wrote:[color=blue]
          > Thanks you! that did it.
          >[/color]

          That makes me wonder what socket.gethostn ame() was returning.
          It wasn't 'localhost', was it?

          Steve

          Comment

          • Philippe C. Martin

            #6
            Re: socket question

            Yes it was.

            Regards,

            Philippe



            On Mon, 07 Feb 2005 21:30:28 +0000, Steve Horsley wrote:
            [color=blue]
            > Philippe C. Martin wrote:[color=green]
            >> Thanks you! that did it.
            >>[/color]
            >
            > That makes me wonder what socket.gethostn ame() was returning.
            > It wasn't 'localhost', was it?
            >
            > Steve[/color]

            Comment

            • Philippe C. Martin

              #7
              Re: socket question

              Thanks, it was a bind problem: socket.gethostn ame() returns 'localhost'
              where '' is was was needed.

              Regards,

              Philippe



              On Mon, 07 Feb 2005 11:02:13 -0800, Kartic wrote:
              [color=blue]
              >
              > Philippe C. Martin wrote:[color=green][color=darkred]
              >> >> My problem is that I cannot connect to my server if the client is[/color][/color]
              > not on[color=green][color=darkred]
              >> >> the same PC (although I'm doing the above).[/color][/color]
              >
              >
              > Does the machine running the server code also have a firewall installed
              > that blocks access to the server port from outside? That is the only
              > possibility I can think of that prevents a non-local client from
              > connecting.
              >
              > Also, please do a netstat -a on the machine running the server and see
              > the IP addresses to which the listening port is bound.
              >
              > Thanks,
              > -Kartic[/color]

              Comment

              Working...