-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8-server.py
33 lines (25 loc) · 945 Bytes
/
8-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
33
import socket
import time
my_ip = "212.104.229.115"
def current_milli_time():
return round(time.time() * 1000)
def start_server():
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# server_socket.bind(('127.0.0.1', 12345))
server_socket.bind((my_ip, 12345))
server_socket.listen(1)
print("Server is listening...")
conn, addr = server_socket.accept()
print("Connection from:", addr)
with open('received_file.txt', 'wb') as file:
last_bw_time = current_milli_time()
data_count = 0
while True:
data = conn.recv(1024)
if not data:
break
file.write(data)
print("File received successfully.")
time.sleep(10)
conn.close()
start_server()