| 1234567891011121314151617181920212223242526272829303132333435363738 |
- # -*- coding: utf-8 -*-
- from socket import *
- from time import ctime
- from AppendClient import AppendClient
- # 服务配置
- HOST = '172.16.102.9'
- PORT = 10087
- # HOST = '127.0.0.1'
- # PORT = 49900
- BUFSIZE = 81920
- ADDR = (HOST, PORT)
- userList = []
- MAXCLIENT = 2
- def loopServer(tcpSrvSock):
- # 服务监听
- global userList, MAXCLIENT
- while True:
- print('Waiting For Client Connection ...', ctime())
- tcpCliSock, addr = tcpSrvSock.accept() # 会阻塞
- print('NewUser', addr, ctime())
- print('UserListLenght:', len(userList))
- # 增加线程
- if tcpCliSock not in userList and len(userList) < MAXCLIENT:
- newClinet = AppendClient(userList, tcpCliSock, BUFSIZE, addr)
- newClinet.start()
- else:
- # 不允许连接
- print('不允许连接')
- tcpCliSock.close()
- if __name__ == '__main__':
- tcpSrvSock = socket(AF_INET, SOCK_STREAM)
- tcpSrvSock.bind(ADDR)
- tcpSrvSock.listen(1)
- loopServer(tcpSrvSock)
|