-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
45 lines (33 loc) · 1.46 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
#---------------------------------------------------------------------------------------
# Terminal Server for remotely debugging my Flet apps.
# (C) Motti Bazar
# You are welcome to use this freely but if you enhance in any way, please repost back.
# If you distribute the code, please include credit to me.
#---------------------------------------------------------------------------------------
import socket
# Server config
host = '172.16.254.133' # Insert terminal server IP here
port = 12345
# Create socket object
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Bind the socket to a specific address and port
server_socket.bind((host, port))
while True:
server_socket.listen(5) # Listen for connection
print(f"Server listening on {host}:{port}")
client_socket, client_address = server_socket.accept() # Accept connection
print(f"Connection established with {client_address}")
while True:
try:
data = client_socket.recv(1024) # Receive data from the client
except:
print("Connection probably closed by the client. Exiting...")
break
if not data:
print("No data received. Somekind of issue. Exiting...")
break
print(data.decode())
# Close the connection
client_socket.close()
print("-"*50)
server_socket.close()