- Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathsimpleChatServer.py
More file actions
Latest commit
52 lines (43 loc) · 1.17 KB
/
Copy pathsimpleChatServer.py
File metadata and controls
52 lines (43 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
"""
An echo server that uses select to handle multiple clients at a time.
Entering any line of input at the terminal will exit the server.
"""
importselect
importsocket
importsys
importtime
importcommands
host=''
port=1235
backlog=5
size=1024
server=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((host,port))
server.listen(5)
input= [server,sys.stdin]
running=1
whilerunning:
# while answer != 'quit':
inputready,outputready,exceptready=select.select(input,[],[])
forsininputready:
ifs==server:
# handle the server socket
client, address=server.accept()
input.append(client)
elifs==sys.stdin:
# handle standard input
junk=sys.stdin.readline()
running=0
else:
# handle all other sockets
data=s.recv(size)
ifdata:
s.send(data)
commands.getstatusoutput('say -v Zarvox %s'%''.join(data.strip()))
time.sleep(0.5)
printdata
else:
s.close()
input.remove(s)
server.close()