Simple socket loop

Martin Skøtt mskott at image.dk
Sun Jan 23 16:02:58 EST 2000


Hi
I'm trying to create a simple socket listener interface but i don't
know how to keep it listening. I have the following server loop (from
the python library reference):
from socket import *
HOST = ''
PORT = 50007
s = socket(AF_INET, SOCK_STREAM)
s.bind(HOST, PORT)
s.listen(2)
conn, addr = s.accept()
print 'Connected by', addr
while 1:
    data = conn.recv(1024)
    if not data: break
    conn.send(data)
conn.close()

After having communicated with the client the server stop! How can I
prevent that and keep it listening (and answering)? I guess I have to
put it inside some kidn of loop but how. Please if you could give me a
working example (or a link to one) it would be great because i'm still
new to Python.

-- 
Many regards
Martin Skøtt
mskott at image.dk

"Every time I learn something new it pushes some old suff out of my brain"
Homer Simpson



More information about the Python-list mailing list