当前位置: 首页>>代码示例>>Python>>正文


Python Channel.multicast方法代码示例

本文整理汇总了Python中channel.Channel.multicast方法的典型用法代码示例。如果您正苦于以下问题:Python Channel.multicast方法的具体用法?Python Channel.multicast怎么用?Python Channel.multicast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在channel.Channel的用法示例。


在下文中一共展示了Channel.multicast方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Process

# 需要导入模块: from channel import Channel [as 别名]
# 或者: from channel.Channel import multicast [as 别名]
class Process(multiprocessing.Process):
    """
        This process could take arguments from command line and execute unicast/multicast actions.
        It can also receive messages from its channel.
    """

    def __init__(self, id, ordering):
        super(Process, self).__init__() # call __init__ from multiprocessing.Process
        self.id = id

        # Read config from file
        self.process_info, self.addr_dict = configreader.get_processes_info()
        address = self.process_info[id]
        ip, port = address[0], address[1]
        print(ip, port)

        # Init a socket
        self.socket = socket.socket(
            socket.AF_INET, socket.SOCK_DGRAM)
        self.socket.bind(address)

        # Init channel

        # Causal Order Channel
        if ordering == 'causal':
            print 'causal ordering'
            self.channel = CausalOrderChannel(self, self.id, self.socket, self.process_info, self.addr_dict)
        elif ordering == 'total':
            print 'total ordering'
            # Total Order Channel
            if id == 1:
                # Select process 1 to be the sequencer
                self.channel = TotalOrderChannel(self, self.id, self.socket, self.process_info, self.addr_dict, True)
            else:
                self.channel = TotalOrderChannel(self, self.id, self.socket, self.process_info, self.addr_dict)
        else:
            # Regular channel
            print 'no ordering'
            self.channel = Channel(self, self.id, self.socket, self.process_info, self.addr_dict)

    def run(self):
        while True:
            data, address = self.socket.recvfrom(4096)
            self.channel.recv(data, address)

    def unicast_receive(self, source, message):
        print (message.receive_str())

    def unicast(self, destination, message):
        self.channel.unicast(message, destination)

    def multicast(self, message):
        self.channel.multicast(message)
开发者ID:weiyangedward,项目名称:cs425_MP,代码行数:55,代码来源:process.py


注:本文中的channel.Channel.multicast方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。