本文整理匯總了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)