main.py 857 B

12345678910111213141516171819202122232425262728293031323334
  1. from socket import *
  2. from time import ctime
  3. from comCation import ComCationServer
  4. # 服务配置
  5. HOST = '172.16.102.9'
  6. PORT = 10087
  7. ADDR = (HOST, PORT)
  8. userList = []
  9. def loopServer(SOCK):
  10. # 服务监听
  11. global userList
  12. while True:
  13. print('Waiting For Client Connection ...', ctime())
  14. client, addr = SOCK.accept() # 会阻塞
  15. print('NewUser', addr, ctime())
  16. # 增加线程
  17. if client not in userList and len(userList) < 2:
  18. userList.append(client)
  19. # 接收
  20. newClinet = ComCationServer(client, userList)
  21. newClinet.start()
  22. else:
  23. # 不允许连接
  24. print('不允许连接')
  25. client.close()
  26. if __name__ == '__main__':
  27. SOCK = socket(AF_INET, SOCK_STREAM)
  28. SOCK.bind(ADDR)
  29. SOCK.listen(1)
  30. loopServer(SOCK)