a simple tcp server sample

Robert Hicks sigzero at gmail.com
Wed Nov 7 14:36:31 EST 2007


On Nov 7, 1:54 pm, Tzury Bar Yochay <Afro.Syst... at gmail.com> wrote:
> 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()

POE




More information about the Python-list mailing list