Hello everyone.
I'm wirting an application for an LPC Controller using Keil/Arm MDK and BSD Sockets.
In the application I close a TCP listen socket and want to reopen it a short time later. I get an Error trying after closing it and trying to bind the newly created Socket: BSD_EADDRINUSE (-17). Seems to indicate that it is in something of a TIME_WAIT state, so I can't reuse that port until the set time passed.
This would be perfectly fine for a connection socket. But for a listen socket, I don't see the point. After closing it no connection would be accepted any more anyway. setsockopt() exists but SO_REUSEADDR is not implemented by the MDK. So how would I try to work around this?
Thanks for any help.
Please install and check the CMSIS-Driver_Validation pack and see SockServer.c in the .\Tools\SockServer\Embedded\MDK\Source folder.
This server performs several services (ECHO, DISCARD, CHARGEN, ..) using BSD sockets. The StreamServer thread is waiting for any connection using the select() function. StreamServer then accepts the connection and creates a new thread that manages the connection until it is closed. The current configuration can accept 5 simultaneous connections: two for ECHO, two for CHARGEN and one for the DISCARD service.
I believe this is what you are looking for.
Solved! Finally.
The BSD Sockets API was working all the time. I just had to understand that after accepting a connection request it was NOT instantly removed from the queue that wast started with listen(<socket>, <queue size>);. So to have two connections simultaneously, 1 didn't do.
I'll mark Franc's answer as the accepted one since that led me to realize my error.
Thank both of you very much.