This server, which is running in a separate thread, seemingly functions well except for the frequently thrown exception "accept: Already open exception". This exception is thrown on acceptor.accept(...) call, on checking whether the socket is already open. If I call the accepter.accept(...) iff socket is not open (commented line), the behaviour becomes unpredictable. The run method gets data from a synchronized mQueue, which is being filled on another thread at about 30 times per second.

1 Answer
1

In asio terms, a socket is "open" if it has a valid socket handle (descriptor). When you accepting an incoming connection, you should pass to the acceptor a "fresh", unopen socket.
So, the problem is in the logic of your code: you should first accept a new connection from your client, and then you can use the accepted socket to send/receive any data you want.