-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
33 lines (30 loc) · 923 Bytes
/
server.py
File metadata and controls
33 lines (30 loc) · 923 Bytes
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
import socket
from select import select
def bind_socket(port):
s = socket.socket()
s.bind(("127.0.0.1", int(port)))
s.listen(10)
conn, addr = s.accept()
return conn
# while True:
# conn, addr = s.accept()
# while True:
# data = conn.recv(1024)
# if not data or data == "close":
# break
# print("Port {}: {}".format(port, data))
# conn.send(data)
# conn.close()
if __name__ == "__main__":
readsocks = [bind_socket(x) for x in ["1234", "1235"]]
writesocks = readsocks
while True:
readables, writeables, exceptions = \
select(readsocks, [], [])
for sockobj in readables:
data = sockobj.recv(512)
if not data:
sockobj.close()
readsocks.remove(sockobj)
else:
print(id(sockobj), ":", data)