Plz help..SocketServer UDP server losing lots of packets
James Mills
prologic at shortcircuit.net.au
Wed Nov 5 19:46:52 EST 2008
On Thu, Nov 6, 2008 at 9:53 AM, <id.engg at gmail.com> wrote:
> 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()
This is horrible code :/
Try these instead:
* UDPServer ->
http://trac.softcircuit.com.au/circuits/browser/examples/udpserver.py
* UDPClient ->
http://trac.softcircuit.com.au/circuits/browser/examples/udpclient.py
Example usage
----------------------
~/circuits/examples
$ ./udpserver.py
127.0.0.1, 9000:
test
127.0.0.1, 9000:
hi
~/circuits/examples
$ ./udpclient.py -b 127.0.0.1:9000 127.0.0.1:8000
test
127.0.0.1, 8000:
test
hi
127.0.0.1, 8000:
hi
You can download circuits from http://trac.softcircuit.com.au/circuits/
or get the latest development version by using Mercurial (1):
hg clone http://hg.softcircuit.com.au/projects/circuits/
cheers
James
[1] http://www.selenic.com/mercurial/wiki/
--
--
-- "Problems are solved by method"
More information about the Python-list
mailing list