TractorVision初期移植

This commit is contained in:
CHAMPION923
2025-05-30 16:30:37 +08:00
commit 2acf920a87
36 changed files with 3898 additions and 0 deletions

0
lib/tcp/__init__.py Normal file
View File

26
lib/tcp/tcp_server.py Normal file
View File

@@ -0,0 +1,26 @@
import socket
class TcpServer:
def __init__(self, host="0.0.0.0", port=65444) -> None:
self.host = host
self.port = port
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.bind((self.host, self.port))
self.sock.listen(1) # 允许最多一个连接(可改大)
print(f"Listening on {self.host}:{self.port}")
def accept_client(self):
self.conn, self.addr = self.sock.accept()
print(f"Connected by {self.addr}")
def recv_data(self, bufsize=4096):
data = self.conn.recv(bufsize)
return data
def send_data(self, data: bytes):
self.conn.sendall(data)
def close(self):
self.conn.close()
self.sock.close()