471,325 Members | 1,704 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

Twisted: UDP socket not closed.


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])

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

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

knight@rknb:~$ ls -la /proc/15429/fd/ | wc -l
knight@rknb:~$ ls -la /proc/15429/fd/ | wc -l
knight@rknb:~$ ls -la /proc/15429/fd/ | wc -l
knight@rknb:~$ ls -la /proc/15429/fd/ | wc -l
knight@rknb:~$ ls -la /proc/15429/fd/ | wc -l
knight@rknb:~$ ls -la /proc/15429/fd/ | wc -l
knight@rknb:~$ ls -la /proc/15429/fd/ | wc -l

Thanks in advance.
Dec 22 '07 #1
0 1034

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Diez B. Roggisch | last post: by
11 posts views Thread by mir nazim | last post: by
1 post views Thread by Tim Gosselin | last post: by
4 posts views Thread by DreJoh | last post: by
2 posts views Thread by Droopy | last post: by
11 posts views Thread by hazz | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.