Twisted: UDP socket not closed.

Luther Edwards le9642 at att.com
Thu Apr 19 21:29:14 EDT 2012


Did anyone in the group ever have an answer to Kevac's question, I'm having a similar issue?

Thanks in advance, Luther

[Python] Twisted: UDP socket not closed.
[cid:image001.png at 01CD1E6B.15DF6BB0]<http://grokbase.com/user/Kevac-Marko/tTjuHcXzmQtuttsnhLfi5e>

Kevac Marko<http://grokbase.com/user/Kevac-Marko/tTjuHcXzmQtuttsnhLfi5e>
Dec 22, 2007 at 9:02 am<http://grokbase.com/g/python/python-list/2007/12>

Hi.

I have to send UDP packets very often. Approx twice in a second.
But socket is not closed after sending packet. So soon i bump into
open sockets\files limit.
How to close socket after sending data?

Python 2.5, Twisted

class DataClient(DatagramProtocol):

def __init__(self, address, datagram = "PONG"):
self.address, self.datagram = address, datagram

def startProtocol(self):
self.transport.socket.setsockopt(socket.SOL_SOCKET, \
socket.SO_BROADCAST, True)
self.transport.connect(self.address[0], self.address[1])
self.sendDatagram()

def sendDatagram(self):
self.transport.write(self.datagram)
debug("Data client: Sending to %s" % repr(self.address))

while True:
clientprotocol = DataClient(("255.255.255.255", 5999), data)
reactor.listenUDP(0, clientprotocol).stopListening()

knight at rknb:~$ ls -la /proc/15429/fd/ | wc -l
43
knight at rknb:~$ ls -la /proc/15429/fd/ | wc -l
44
knight at rknb:~$ ls -la /proc/15429/fd/ | wc -l
44
knight at rknb:~$ ls -la /proc/15429/fd/ | wc -l
44
knight at rknb:~$ ls -la /proc/15429/fd/ | wc -l
45
knight at rknb:~$ ls -la /proc/15429/fd/ | wc -l
45
knight at rknb:~$ ls -la /proc/15429/fd/ | wc -l
46

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120419/bd97e71f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 1136 bytes
Desc: image001.png
URL: <http://mail.python.org/pipermail/python-list/attachments/20120419/bd97e71f/attachment.png>


More information about the Python-list mailing list