-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server.py
32 lines (28 loc) · 948 Bytes
/
Server.py
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
import socket
if __name__ == '__main__':
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Connect the socket to the port where the server is listening
server_address = ('192.168.0.109', 7777)
print('starting up on %s port %s' % server_address)
sock.bind(server_address)
sock.listen(1)
f = open("acc_reading.txt", "w")
f.write("")
f.close()
while True:
print('waiting for a connection...')
connection, client_address = sock.accept()
try:
print('connection from', client_address)
f = open("acc_reading.txt", "a")
while True:
data = connection.recv(1024)
if data:
f.write(data.decode('utf-8'))
else:
f.close()
break
finally:
print('closing socket')
connection.close()