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.

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@rknb:~$ ls -la /proc/15429/fd/ | wc -l
43
knight@rknb:~$ ls -la /proc/15429/fd/ | wc -l
44
knight@rknb:~$ ls -la /proc/15429/fd/ | wc -l
44
knight@rknb:~$ ls -la /proc/15429/fd/ | wc -l
44
knight@rknb:~$ ls -la /proc/15429/fd/ | wc -l
45
knight@rknb:~$ ls -la /proc/15429/fd/ | wc -l
45
knight@rknb:~$ ls -la /proc/15429/fd/ | wc -l
46

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.