Twisted Matrix and multicast broadcast

2008-10-09 Thread Stodge
I'm trying to get a simple multicast application working using
Twisted; so far I have:

from twisted.internet.protocol import DatagramProtocol
from twisted.internet import reactor
from twisted.application.internet import MulticastServer

class MulticastServerUDP(DatagramProtocol):
def startProtocol(self):
print 'Started Listening'
# Join a specific multicast group, which is the IP we will
respond to
self.transport.joinGroup('224.0.0.1')

def datagramReceived(self, datagram, address):
# The uniqueID check is to ensure we only service requests
from
# ourselves
if datagram == 'UniqueID':
print "Server Received: " + repr(datagram)
self.transport.write("data", address)

# Listen for multicast on 224.0.0.1:8005
reactor.listenMulticast(8005, MulticastServerUDP())
reactor.run()


and:



from twisted.internet.protocol import DatagramProtocol
from twisted.internet import reactor
from twisted.application.internet import MulticastServer

class MulticastClientUDP(DatagramProtocol):
def startProtocol(self):
print 'Started Listening'
# Join a specific multicast group, which is the IP we will
respond to
self.transport.joinGroup('224.0.0.1')

self.transport.write('UniqueID',('224.0.0.1', 8005))

def datagramReceived(self, datagram, address):
print "Received:" + repr(datagram)

# Send multicast on 224.0.0.1:8005, on our dynamically allocated port
reactor.listenMulticast(0, MulticastClientUDP())
reactor.run()



No surprises there! But how do I get the server to send to all clients
using multicast? transport.write requires an address. Any suggestions
appreciated.

Thanks
--
http://mail.python.org/mailman/listinfo/python-list


Re: Twisted Matrix and multicast broadcast

2008-10-09 Thread Jean-Paul Calderone

On Thu, 9 Oct 2008 06:03:44 -0700 (PDT), Stodge <[EMAIL PROTECTED]> wrote:

[snip]
class MulticastServerUDP(DatagramProtocol):
   def startProtocol(self):
   print 'Started Listening'
   # Join a specific multicast group, which is the IP we will
respond to
   self.transport.joinGroup('224.0.0.1')

[snip]

class MulticastClientUDP(DatagramProtocol):
   def startProtocol(self):
   print 'Started Listening'
   # Join a specific multicast group, which is the IP we will
respond to
   self.transport.joinGroup('224.0.0.1')

[snip]

No surprises there! But how do I get the server to send to all clients
using multicast? transport.write requires an address. Any suggestions
appreciated.


Your server and client are both listening on the multicast address
224.0.0.1.  Traffic sent to that address will be delivered to both
of them.  If you want to send something to all clients listening on
that address, then that's the address to pass to transport.write.

Jean-Paul
--
http://mail.python.org/mailman/listinfo/python-list


Re: Twisted Matrix and multicast broadcast

2008-10-09 Thread Stodge
On Oct 9, 9:33 am, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote:
> On Thu, 9 Oct 2008 06:03:44 -0700 (PDT), Stodge <[EMAIL PROTECTED]> wrote:
> > [snip]
> >class MulticastServerUDP(DatagramProtocol):
> >    def startProtocol(self):
> >        print 'Started Listening'
> >        # Join a specific multicast group, which is the IP we will
> >respond to
> >        self.transport.joinGroup('224.0.0.1')
>
> > [snip]
>
> >class MulticastClientUDP(DatagramProtocol):
> >    def startProtocol(self):
> >        print 'Started Listening'
> >        # Join a specific multicast group, which is the IP we will
> >respond to
> >        self.transport.joinGroup('224.0.0.1')
>
> > [snip]
>
> >No surprises there! But how do I get the server to send to all clients
> >using multicast? transport.write requires an address. Any suggestions
> >appreciated.
>
> Your server and client are both listening on the multicast address
> 224.0.0.1.  Traffic sent to that address will be delivered to both
> of them.  If you want to send something to all clients listening on
> that address, then that's the address to pass to transport.write.
>
> Jean-Paul

Thanks. So the server write should be:

self.transport.write("data", ('224.0.0.1', 8005))

I guess I can't run multiple peers on the same PC as they'll all be
listening on port 8005.
--
http://mail.python.org/mailman/listinfo/python-list