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


Python Server._accept方法代码示例

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


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

示例1: run_server

# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import _accept [as 别名]
def run_server(host, port):
    selfServer = Server(host, int(port)) 
    input.append(selfServer.serverSocket) 
    selfServer._listen() 
    running = True

    while running is True: 
        inready,outready,exready = select.select(input,[],[]) 

        for s in inready:
            # Accepting newly discovered connections.
            if s == selfServer.serverSocket:
                clientInformation = selfServer._accept()
                client = clientInformation[0]
                input.append(client)
                users.update({client:[None,clientInformation[1], False]})
                pendingClients.append(client)
            # Receiving data from a client, if client is no longer sending data,
            # they are no longer connected (remove them).
            # This will write to all connected clients!
            if s in clientList:
                data = s.recv(SIZE)
                name = users.get(s)[0]
                if data:
                    tempData = data.rstrip("\r\n")
                    splitData = tempData.split(" ", 1)
                    splitData.append("\n") # Placeholder to fix argument issues...
                    if splitData[0] in commandDict.keys():
                        commandDict[splitData[0]](s, splitData[1])
                    else:
                        line = name + ": " + data
                        print line
                        for client in clientList:
                            if client is not s:
                                client.send(line)
                else: 
                    cleanup(s)
                    print ERROR_MSG['leaveMsg'].format(name=name)
                    for client in clientList:
                        if client is not s:
                            client.send(ERROR_MSG['leaveMsg'].format(name=name))
            if s in pendingClients:
                data = s.recv(SIZE)
                if data:
                    tempData = data.rstrip("\r\n")
                    splitData = tempData.split(" ", 1)
                    splitData.append("\n")
                    if splitData[0] == "/name":
                        commandDict[splitData[0]](s, splitData[1])
                        pendingClients.remove(s)
                        clientList.append(s)
                else:
                    pass 
    selfServer._close()
开发者ID:elizabethnguyen,项目名称:chat-client,代码行数:56,代码来源:chat-client.py


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