IO 库问题 #127
转发: IO Library Issue
项目介绍
“IO 库问题 #127:listen() 函数中的套接字关闭错误”
各种问题中最突出的问题之一是在 socket.c 文件中的 Listen() 函数中确定的。 读取 getSn_SR(sn); 时会出现问题 如果 TCP 连接已经建立,则会导致套接字关闭状态。
经测试,正常情况下不会出现该问题。 然而,在第 254 行之前引入大约 1 秒的延迟会触发该问题。 在这种情况下,getSn_SR(sn) 输出 SOCK_ESTABLISHED 而不是 SOCK_LISTEN,从而导致套接字关闭。
When observing the serial output, errors become evident as described below.
我已进行以下更改,并已提交包含更改的 Pull 请求。
以下是用于测试的 Python 代码:
import socket
import threading
# Server IP address and port number
server_ip = "192.168.100.109"
server_port = 5000
# Create a socket
def create_client():
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
# Attempt to connect to the server
client_socket.connect((server_ip, server_port))
print(f"Connected to the server: {server_ip}:{server_port}")
except Exception as e:
print(f"Error occurred during connection attempt: {e}")
finally:
# Close the client socket
client_socket.close()
# Create and run multiple clients
num_clients = 10 # Number of clients to create
threads = []
for _ in range(num_clients):
thread = threading.Thread(target=create_client)
thread.start()
threads.append(thread)
# Wait for all threads to finish
for thread in threads:
thread.join()
请随意提供任何其他背景或详细信息,我很乐意提供进一步帮助。
IoLibrary问题: https://github.com/Wiznet/ioLibrary_Driver/issues/127