[Twisted-Python] udp broadcast question
Gaspard, Bradley S
BRADLEY.S.GASPARD at saic.com
Tue Oct 24 16:27:50 EDT 2006
I found a udp broadcast example (below) which works fine for my wired
ethernet interface but I would like to be able to specify my wireless
interface (ath0) for the udp broadcast. How can this be done?
On Wednesday, Dec 17, 2003, at 17:27 Europe/Helsinki, Jp Calderone
> No threads, but maybe it's good enough anyway:
Thanks for trying to help. But really this is very incomplete, missing
all read or write calls to the socket.
And I've tried, with just that SO_BROADCAST option I do not receive the
stuff I send, and in fact with just that option, I can't even send.
But thanks for the pointer to twisted.
> import sys
> from socket import SOL_SOCKET, SO_BROADCAST
> from twisted.internet import reactor
> from twisted.internet import protocol
> from twisted.internet import task
> from twisted.python import log
> port = 7154
> class BroadcastingDatagramProtocol(protocol.DatagramProtocol):
> port = port
> def startProtocol(self):
> self.transport.socket.setsockopt(SOL_SOCKET, SO_BROADCAST,
> self.call = task.LoopingCall(self.tick)
> self.dcall = self.call.start(1.0)
> def stopProtocol(self):
> def tick(self):
> self.transport.write(self.getPacket(), ("<broadcast>",
> def getPacket(self):
> return "Some bytes for you"
> def datagramReceived(self, data, addr):
> print "Received", repr(data)
> reactor.listenUDP(port, BroadcastingDatagramProtocol())
More information about the Twisted-Python