本文整理汇总了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()