Plz help..SocketServer UDP server losing lots of packets

id.engg at gmail.com id.engg at gmail.com
Wed Nov 5 18:53:23 EST 2008


logFileName = 'log.txt'
        logfile = open(logFileName, "a")
        class MyUDPServer(SocketServer.UDPServer):
                def server_bind(self):
                        self.socket.setsockopt(socket.SOL_SOCKET,
socket.SO_RCVBUF, 8388608)
                        self.socket.bind(self.server_address)

        class LogsDumpHandler(SocketServer.DatagramRequestHandler):
                def handle(self):
                        global logfile
# fileExists is a function which checks the existence of a file
                        if not fileExists(logFileName):
                                logfile = open(logFileName, "a")
                        logfile.writelines(self.rfile.readlines())

        server = MyUDPServer(("",PORT), LogsDumpHandler)
        server.serve_forever()
        logfile.close()

The above python code is a UDP server based on SocketServer framework
and I am losing a lot of messages, I have tried almost everything,
increasing the size of the receive buffer, changing the way i read the
messages coming into server.
The above code is supposed to work as a tracing server and it does but
is losing messages.
Is there a way I can improve this code?
Any help will be highly appreciated.

Thanks,
Sam



More information about the Python-list mailing list