(host, port, num)
处理连接，num为流编号（第0号还是第1号）
	@note: 如果连接不到远程，会sleep 36s，最多尝试200(即两小时)
处理连接，num为流编号（第0号还是第1号）
处理连接，num为流编号（第0号还是第1号）
def _connect(host, port, num):
	'''	处理连接，num为流编号（第0号还是第1号）
	@note: 如果连接不到远程，会sleep 36s，最多尝试200(即两小时)
	'''
	not_connet_time = 0
	wait_time = 36
	try_cnt = 199
	while True:
		if not_connet_time > try_cnt:
			streams[num] = 'quit'
			print('not connected')
			return None

		conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
		try:
			conn.connect((host, port))
		except Exception, e:
			print ('can not connect %s:%s!' % (host, port))
			not_connet_time += 1
			time.sleep(wait_time)
			continue

		print "connected to %s:%i" % (host, port)
		streams[num] = conn  #放入本端流对象
		s2 = _get_another_stream(num) #获取另一端流对象
		_xstream(num, conn, s2)
def _connect ( host , port , num ) : not_connet_time = 0 wait_time = 36 try_cnt = 199 while True : if not_connet_time > try_cnt : streams [ num ] = 'quit' print ( 'not connected' ) return None conn = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) try : conn . connect ( ( host , port ) ) except Exception , e : print ( 'can not connect %s:%s!' % ( host , port ) ) not_connet_time += 1 time . sleep ( wait_time ) continue print "connected to %s:%i" % ( host , port ) streams [ num ] = conn #放入本端流对象 s2 = _get_another_stream ( num ) #获取另一端流对象 _xstream ( num , conn , s2 )