from socket import * from time import ctime from comCation import ComCationServer # 服务配置 HOST = '172.16.102.9' PORT = 10087 ADDR = (HOST, PORT) userList = [] def loopServer(SOCK): # 服务监听 global userList while True: print('Waiting For Client Connection ...', ctime()) client, addr = SOCK.accept() # 会阻塞 print('NewUser', addr, ctime()) # 增加线程 if client not in userList and len(userList) < 2: userList.append(client) # 接收 newClinet = ComCationServer(client, userList) newClinet.start() else: # 不允许连接 print('不允许连接') client.close() if __name__ == '__main__': SOCK = socket(AF_INET, SOCK_STREAM) SOCK.bind(ADDR) SOCK.listen(1) loopServer(SOCK)