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


Python Server.add_server_to_network方法代码示例

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


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

示例1: PiggyNetwork

# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import add_server_to_network [as 别名]
class PiggyNetwork():

	host = '127.0.0.1'
	base_port = 50000
	base_data_path = "/primary_data.txt"
	base_backup_path = "/backup_data.txt"
	# Defining the workload per server. In this case clients with last names A-M are processed by server 1 #
	# and clients with last names N-Z are processed by server 2 #
	total_workload = list(string.ascii_uppercase)

	# Initialize our Network with two servers, with divided workloads, and their relevant data paths. Each server is then #
	# added to the other's detectable network                                                                             #
	def __init__(self):
		self.server1 = Server(self.base_port, self.total_workload[:14], "server1" + self.base_data_path, "server1" + self.base_backup_path)
		self.server2 = Server(self.base_port + 1, self.total_workload[14:], "server2" + self.base_data_path, "server2" + self.base_backup_path)
		self.server1.add_server_to_network(self.server2)
		self.server2.add_server_to_network(self.server1)

	# Getters #
	def get_server1(self):
		return self.server1

	def get_server2(self):
		return self.server2
	# End Getters #

	# Multi-Threaded Functionality #
	def boot_server(self, server):
		server.listen()

	def initialize(self):
		thread1 = threading.Thread(target=self.boot_server, args=(self.server1,))
		thread2 = threading.Thread(target=self.boot_server, args=(self.server2,))
		thread1.start()
		thread2.start()
开发者ID:arjungupta291,项目名称:AJ-Code-Samples,代码行数:37,代码来源:PiggyNetwork.py


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