35 lines
841 B
Python
35 lines
841 B
Python
#!/usr/bin/env python3
|
|
|
|
import socket
|
|
import fcntl
|
|
import array
|
|
import termios
|
|
|
|
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
|
|
server.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1500)
|
|
server.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1500)
|
|
|
|
server.bind(("0.0.0.0", 54248))
|
|
server.listen(32)
|
|
|
|
while True:
|
|
client, addr = server.accept()
|
|
print("Got connection")
|
|
try:
|
|
with client:
|
|
client.sendall(b"ping")
|
|
print("Message sent")
|
|
|
|
buf = array.array("h", [0])
|
|
fcntl.ioctl(client.fileno(), termios.TIOCOUTQ, buf)
|
|
while buf[0] != 0:
|
|
fcntl.ioctl(client.fileno(), termios.TIOCOUTQ, buf)
|
|
|
|
print("Received message ack")
|
|
|
|
# print(client.recv(24))
|
|
except Exception as e:
|
|
client.close()
|
|
print(e)
|