tcp

Gif pavloutefkros at gmail.com
Sun Mar 2 08:09:10 EST 2008


i have this small script which after some router configurations works.

##########################################################

#! /usr/bin/python
import socket

HOST = ''
PORT = 1515
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
conn.send('HTTP/1.1 200 OK\r\n')
conn.send('Content-Type: text/html\r\n')
conn.send('Server: test/1.0\r\n\r\n')
conn.send('<html><body>test</body></html>')
s.close()

##########################################################

as you see it listens to 1515 until a connection is established and
then it accepts it...
the problem is that when it accepts the connection it sends those
strings and exits, but then it exits the program. i want it to listen
to 1515 then accept a connection, send.. and then listen to the port
again and again until new connections are found.

i've been struggling with try..except,while and all kinds of loops but
always new erros pop up, or it overflows.



More information about the Python-list mailing list