UnixDatagramServer
Jim Dennis
jimd at vega.starshine.org
Wed Apr 3 06:00:28 EST 2002
What part am I missing:
#!/usr/bin/env python2.2
import SocketServer, sys, os, socket
class USrvr(SocketServer.UnixDatagramServer): pass
class RHandler(SocketServer.BaseRequestHandler):
num = 0
def handler(self):
conn = self.request
msg = []
while 1:
data = conn.recv(65535)
if not data: break
msg.append(data)
self.messages.append(msg)
self.wfile.write("%s\r\n" % self.num)
self.num += 1
if __name__ == "__main__":
try: os.unlink("/tmp/svr.socket")
except: pass
svr = USrvr("/tmp/svr.socket", RHandler)
svr.serve_forever()
I'm just trying to write a server (Unix domain sockets) that
will be a blackhole for any text send to it and return an
incremented integer for every new connection/transaction.
It runs, it seems to bind to the socket and accept connections
on it. (I can see the socket open in lsof and I can run the following
commands from an interactive session:
from socket import *
a = socket(AF_UNIX, SOCK_DGRAM)
a.connect('/tmp/svr.socket')
a.send('tst')
3
a.recv(1)
... and it simply blocks.
So, the question is how to I get a response back!
More information about the Python-list
mailing list