Platform: UNC20 OS: NET+OS v5.1, ThreadX Basic Idea of client side code: MyThread { while(1) { S = Create socket(); Connect Socket(S); Close Socket(S); } } This code works until the socket number S reaches 128 which is the MAX_SOCKET value. My question is why Close Socket don’t seem to free the socket S or why create socket() dosen’t generate working socket after 127. Last part of debug sequence: loop 124 S = Create socket(); –> S = 126 Connect Socket(126); Close Socket(126); loop 125 S = Create socket(); –> S = 127 Connect Socket(127); Close Socket(127); loop 126 S = Create socket(); –> S = -1 –> Create socket fails ! Create socket keeps failing until system reboot. Any comments would be very appreciated
Are you by any chance using more than that thread? I am thinking you have another thread reading from the socket in a block recv call. If that is the case close socket wont really close the socket. The read thread needs to exit the recv call before you can close. Hope this helps you.
Thanks for your reply but no other threads are using the connect rutine. I’ve singled out this one thread for debugging purposes but still I get the specified effect. I’ve tried to reconnect to a “closed socket” and that won’t work so at least the socket i half closed.
Did you try to put a delay after closesocket()?
Yes, before and after the close socket in different combinations. Does anyone know how the “int mySocket = socket(parameters)” function works. Is it suppose to generate an incremented socket value, random available socket or lowest available. My function use keeps returning an increment of previous value until it reaches 127 and then fails.
I am using sockets in the following way: I have a socket open permanently and listening for connections. Whenever it gets a client connected to it, the system opens another socket and connect it to the client. Then, the main socket continue to isten for new incoming connections. When the client closes the communication the socket open for that client is closed. I can open and close more than 128 sockets. I always shutdown the socket before closing (with the second parameter set to 2). I am using NS9750 and NetOS 6.3, but other versions should be similar. Try to use the latest patches available for your OS.
Thanks for your suggestions Adrian but no help.