a simple tcp server sample

Tzury Bar Yochay Afro.Systems at gmail.com
Wed Nov 7 13:54:39 EST 2007


hi, the following sample (from docs.python.org) is a server that can
actually serve only single client at a time.

In my case I need a simple server that can serve more than one client.
I couldn't find an example on how to do that and be glad to get a
hint.

Thanks in advance

import socket

HOST = '127.0.0.1'      # Symbolic name meaning the local host
PORT = 50007            # Arbitrary non-privileged port

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()

print 'Connected by', addr

while 1:
        data = conn.recv(1024)
        if not data:
                break
        conn.send(data)

conn.close()




More information about the Python-list mailing list