Spaces:
Runtime error
Runtime error
Commit
•
2648b2e
1
Parent(s):
9b77346
Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,29 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import socket
|
2 |
+
|
3 |
+
# Set up a TCP/IP server
|
4 |
+
tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
5 |
+
|
6 |
+
# Bind the socket to server address and port 50052
|
7 |
+
server_address = ('localhost', 50052)
|
8 |
+
tcp_socket.bind(server_address)
|
9 |
+
|
10 |
+
# Listen on port 50052
|
11 |
+
tcp_socket.listen(1)
|
12 |
+
|
13 |
+
while True:
|
14 |
+
print("Waiting for connection")
|
15 |
+
connection, client = tcp_socket.accept()
|
16 |
+
|
17 |
+
try:
|
18 |
+
print("Connected to client IP: {}".format(client))
|
19 |
+
|
20 |
+
# Receive and print data 32 bytes at a time, as long as the client is sending something
|
21 |
+
while True:
|
22 |
+
data = connection.recv(32)
|
23 |
+
print("Received data: {}".format(data))
|
24 |
+
|
25 |
+
if not data:
|
26 |
+
break
|
27 |
+
|
28 |
+
finally:
|
29 |
+
connection.close()
|