Boost::asio server/client socket, access permissions and ports issue

狂风中的少年 提交于 2019-12-30 11:24:06

问题


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:

  1. 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.
  2. 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).
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!