Wiznet makers

irina

Published November 21, 2023 ©

91 UCC

3 WCC

86 VAR

0 Contests

0 Followers

0 Following

IO Library Issue

IO Library Issue #127

COMPONENTS
PROJECT DESCRIPTION

"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

 

Documents
Comments Write