logFileName = 'log.txt'
logfile = open(logFileNam e, "a")
class MyUDPServer(Soc ketServer.UDPSe rver):
def server_bind(sel f):
self.socket.set sockopt(socket. SOL_SOCKET,
socket.SO_RCVBU F, 8388608)
self.socket.bin d(self.server_a ddress)
class LogsDumpHandler (SocketServer.D atagramRequestH andler):
def handle(self):
global logfile
# fileExists is a function which checks the existence of a file
if not fileExists(logF ileName):
logfile = open(logFileNam e, "a")
logfile.writeli nes(self.rfile. readlines())
server = MyUDPServer(("" ,PORT), LogsDumpHandler )
server.serve_fo rever()
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
logfile = open(logFileNam e, "a")
class MyUDPServer(Soc ketServer.UDPSe rver):
def server_bind(sel f):
self.socket.set sockopt(socket. SOL_SOCKET,
socket.SO_RCVBU F, 8388608)
self.socket.bin d(self.server_a ddress)
class LogsDumpHandler (SocketServer.D atagramRequestH andler):
def handle(self):
global logfile
# fileExists is a function which checks the existence of a file
if not fileExists(logF ileName):
logfile = open(logFileNam e, "a")
logfile.writeli nes(self.rfile. readlines())
server = MyUDPServer(("" ,PORT), LogsDumpHandler )
server.serve_fo rever()
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
Comment