问题
A new error arose with my server (boost::asio based) once I implemented reconnection on my client but I am not even sure if this is the cause. The scenario is like this:
- I run Client.exe which can reconnect in case a server is not running. Client.exe creates several objects which connect independently to my server. So several connections to my servers are created from the same process.
- Because I haven't run the server yet, every object try to reconnect every 3 seconds (some of them concurrently so not always at the same time).
- The problem occurs sometimes when I start the server: I get the "An attempt was made to access a socket in a way forbidden by its access permissions" error.
Looking with TCPView I found that everything looks good and it works. The server listen on the port 7000. But when this problem arises I can see a weird thing with TCPView:
Client.exe 9016 TCP ME 7000 localhost 7000 ESTABLISHED
How is this possible while the server is not running? same port? I checked and there is no other process listening on this port! How can exists and ESTABLISHED connection on the 7000 port if there is nothing on the other side listening. Then, of course, the port is in use by the client and I get this error (not really sure why I get this error and not something like "port already in use".
Notes: I do not have antivirus, windows firewall is deactivated and not other process is using the port 7000. I only have a server which listen on port 7000 and a client connecting to the server. After several times stopping (cleanly) and starting the server this weird connection appears.
EDIT: server and client are running on the same machine
来源:https://stackoverflow.com/questions/21481482/boostasio-server-client-socket-access-permissions-and-ports-issue