#サーバー側
server.py
import socket
import numpy as np
import time
PORT = 12345
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
host = (socket.gethostbyname(socket.gethostname()))
print(f"{host = }")
s.bind((host, PORT))
while True:
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.listen(1)
print("listen")
conn, addr = s.accept()
print("accept")
i = 0
while True:
try:
print(f"{i*0.04:.03f}")
i += 1
data = np.zeros(3*64, dtype="int16")
conn.sendall(data)
time.sleep(0.04)
except KeyboardInterrupt:
print('Interrupted.')
break
except:
break
#クライアント側
client.py
import socket
HOST = '172.27.128.1'
PORT = 12345
recv_size = 0
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
print(s.connect((HOST, PORT)))
while 1:
data = s.recv(1024)
recv_size += len(data)
print(len(data), recv_size)