What host do I have to bind a listening socket to?

Posted by herrturtur on Stack Overflow See other posts from Stack Overflow or by herrturtur
Published on 2010-05-27T06:55:27Z Indexed on 2010/05/27 7:01 UTC
Read the original article Hit count: 167

I used python's socket module and tried to open a listening socket using

import socket
import sys

def getServerSocket(host, port):
    for r in socket.getaddrinfo(host, port, socket.AF_UNSPEC,
                                socket.SOCK_STREAM, 0, socket.AI_PASSIVE):
        af, socktype, proto, canonname, sa = r
        try:
            s = socket.socket(af, socktype, proto)
        except socket.error, msg:
            s = None
            continue
        try:
            s.bind(sa)
            s.listen(1)
        except socket.error, msg:
            s.close()
            s = None
            continue
        break
    if s is None:
        print 'could not open socket'
        sys.exit(1)
    return s

Where host was None and port was 15000.

The program would then accept connections, but only from connections on the same machine. What do I have to do to accept connections from the internet?

© Stack Overflow or respective owner

Related posts about python

Related posts about networking