[Twisted-Python] udp broadcast question
Gaspard, Bradley S
BRADLEY.S.GASPARD at saic.com
Tue Oct 24 14:27:50 MDT 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
wrote:
>
> 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.
Torsten
> 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
>
> log.startLogging(sys.stdout)
>
> port = 7154
>
> class BroadcastingDatagramProtocol(protocol.DatagramProtocol):
>
> port = port
>
> def startProtocol(self):
> self.transport.socket.setsockopt(SOL_SOCKET, SO_BROADCAST,
> True)
> self.call = task.LoopingCall(self.tick)
> self.dcall = self.call.start(1.0)
>
> def stopProtocol(self):
> self.call.stop()
>
> def tick(self):
> self.transport.write(self.getPacket(), ("<broadcast>",
> self.port))
>
> def getPacket(self):
> return "Some bytes for you"
>
> def datagramReceived(self, data, addr):
> print "Received", repr(data)
>
> reactor.listenUDP(port, BroadcastingDatagramProtocol())
> reactor.run()
>
> Jp
>
> --
> http://mail.python.org/mailman/listinfo/python-list
More information about the Twisted-Python
mailing list