Simple TCP Server || Daemonize || Continuous
Metnetsky
matt at uberstats.com
Tue Feb 4 05:10:09 EST 2003
I found the following code courtesy of the great Python docs (thank you
whomever). I was wondering what I might have to do in order to turn this
simple TCP-server into a *nix daemon, and how to keep the server accepting
continuous connections. I tried playing around with the code to keep it
going, but I'm apparently not completely understanding the code (which I'm
sure I can get). The big thing here is the transformation into a daemon.
How can I make this python script fork itself away from it's parent?
===
#!/usr/bin/python
# Echo server program
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()
===
Thanks in advance,
Matthew Metnetsky
More information about the Python-list
mailing list