Spaces:
Runtime error
Runtime error
File size: 745 Bytes
2648b2e |
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 |
import socket
# Set up a TCP/IP server
tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Bind the socket to server address and port 50052
server_address = ('localhost', 50052)
tcp_socket.bind(server_address)
# Listen on port 50052
tcp_socket.listen(1)
while True:
print("Waiting for connection")
connection, client = tcp_socket.accept()
try:
print("Connected to client IP: {}".format(client))
# Receive and print data 32 bytes at a time, as long as the client is sending something
while True:
data = connection.recv(32)
print("Received data: {}".format(data))
if not data:
break
finally:
connection.close() |