本文整理汇总了Python中Client.connectToServer方法的典型用法代码示例。如果您正苦于以下问题:Python Client.connectToServer方法的具体用法?Python Client.connectToServer怎么用?Python Client.connectToServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Client
的用法示例。
在下文中一共展示了Client.connectToServer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handleNewClientConnections
# 需要导入模块: import Client [as 别名]
# 或者: from Client import connectToServer [as 别名]
def handleNewClientConnections(localPort, tunnelID, destPort):
# print("Listening at port: " + str(localPort))
listen_client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listen_client_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listen_client_socket.bind((LOCALHOST, localPort))
listen_client_socket.listen(5)
sys.stdout.write("Client created: " + tunnelID+"\n")
sys.stdout.flush()
while True:
## new incoming client connection
newClient = None
try:
client_connection, client_address = listen_client_socket.accept()
my_id = uuid.uuid4()
newClient = Client(my_id, client_connection, client_address)
except KeyboardInterrupt:
print("\nClient is being terminated by user!\nClosing connections...")
listen_client_socket.close()
print("bye!")
os._exit(0)
## if connected to server return TRUE else FALSE
if(newClient.connectToServer()):
# print("\nConnection established!")
## new thread to handle communication
## client object and server object
newClient.setDestTunnelId(tunnelID)
serverMsgHanlderThread = Thread(target=ClientServerCommunication, args=[newClient, destPort])
serverMsgHanlderThread.daemon = True
serverMsgHanlderThread.start()
else:
newClient.getConnection().close()