Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
multicast
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
Seb  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 02:03
Newsgroups: comp.lang.python
From: Seb <sebastianthegreat...@gmail.com>
Date: Wed, 4 Nov 2009 18:03:49 -0800 (PST)
Local: Thurs 5 Nov 2009 02:03
Subject: multicast
I'm trying to implement a multicast module. I'm inspired by this blog
http://chaos.weblogs.us/archives/164

I'd like to get some comments on the code so far but more importantly
some suggestions on how I can implement reliable multicasting.

best regards,
Seb


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Seb  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 02:05
Newsgroups: comp.lang.python
From: Seb <sebastianthegreat...@gmail.com>
Date: Wed, 4 Nov 2009 18:05:24 -0800 (PST)
Local: Thurs 5 Nov 2009 02:05
Subject: Re: multicast
Forgot the code... doh! :)

#! /usr/bin/env python

import socket
import time

class MulticastSender(object):
        def __init__(self, MCAST_ADDR = "224.168.2.9", MCAST_PORT = 1600):
                self.MCAST_ADDR = MCAST_ADDR
                self.MCAST_PORT = MCAST_PORT
                ANY = "0.0.0.0"
                SENDERPORT=1501
#create a UDP socket
                self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
socket.IPPROTO_UDP)
#allow multiple sockets to use the same PORT number
                self.sock.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
#The sender is bound on (0.0.0.0:1501)
                self.sock.bind((ANY,SENDERPORT))
#Tell the kernel that we want to multicast and that the data is sent
#to everyone (255 is the level of multicasting)
                self.sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL,
255)

        def send(self, data):
                self.sock.sendto(data, (self.MCAST_ADDR, self.MCAST_PORT));

class MulticastReceiver(object):
        def __init__(self, MCAST_ADDR = "224.168.2.9", MCAST_PORT = 1600):
                ANY = "0.0.0.0"
#create a UDP socket
                self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
socket.IPPROTO_UDP)
#allow multiple sockets to use the same PORT number
                self.sock.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
#Bind to the port that we know will receive multicast data
                self.sock.bind((ANY,MCAST_PORT))
#tell the kernel that we are a multicast socket
                self.sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL,
255)
#Tell the kernel that we want to add ourselves to a multicast group
#The address for the multicast group is the third param
                status = self.sock.setsockopt(socket.IPPROTO_IP,
socket.IP_ADD_MEMBERSHIP, socket.inet_aton(MCAST_ADDR) +
socket.inet_aton(ANY));
                self.sock.setblocking(0)

        def setblocking(self, flag):
                self.sock.setblocking(flag)

        def recv(self, size = 1024):
                return self.sock.recvfrom(size)

class Multicast(object):
        def __init__(self):
                self.__ms = MulticastSender()
                self.__mr = MulticastReceiver()

        def send(self, data):
                self.__ms.send(data)

        def recv(self, size = 1024):
                return self.__mr.recv()

if __name__ == "__main__":
        mc = Multicast()
        while 1:
                try:
                        data, addr = mc.recv()
                except socket.error, e:
                        #print "sock.error: ", e
                        pass
                else:
                        print "FROM: ", addr
                        print "DATA: ", data


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google