可以用python写一个,看看是否满足要求:
[Python] 纯文本查看 复制代码 import socket
# 监听端口接收数据
recv_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
recv_socket.bind(('0.0.0.0', 5000)) # 监听5000端口
recv_socket.listen(1)
conn, addr = recv_socket.accept()
while True:
data = conn.recv(1024)
if data:
# 将十六进制数据转换为字符串
hex_str = data.hex()
print(f"Received: {hex_str}")
# 通过另一个端口发送数据
send_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
send_socket.connect(('127.0.0.1', 6000)) # 向本机其他端口发送数据,如6000
# send_socket.sendall(data) # 发送接收到的十六进制数据
send_socket.sendall(hex_str.encode()) # 发送接收到的十六进制数据字符串
print("已发送")
send_socket.close() |