IO Library Issue
IO Library Issue #127
![](/upload/project/3176/cover122.jpg)
"IO Library Issue #127: Socket Closure Bug in listen() Function"
One of the prominent issues among various concerns is identified within the listen() function in the socket.c file.
The issue arises when reading getSn_SR(sn); if a TCP connection is already established, it leads to a socket closure state.
Upon testing, under normal circumstances, this issue does not manifest.
However, introducing a delay of approximately 1 second before line 254 triggers the problem. In this scenario, getSn_SR(sn) outputs SOCK_ESTABLISHED instead of SOCK_LISTEN, resulting in a socket closure.
When observing the serial output, errors become evident as described below.
I have made the following changes and have already submitted a Pull Request with the alterations.
Here is the Python code utilized for testing:
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()
Feel free to provide any additional context or details, and I'll be happy to assist further.
IoLibrary issue: https://github.com/Wiznet/ioLibrary_Driver/issues/127