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


Python Client.connectToServer方法代码示例

本文整理汇总了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()
开发者ID:cruiz1391,项目名称:Addigy4,代码行数:33,代码来源:Main.py


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