<br><font size=2 face="sans-serif">I have a server where there must be
only one instance of it for a given machine on a given port number. Here
is the code I used to try to make that happen:</font>
<br>
<br><font size=1 face="Courier New">boost::asio::io_service ios;</font>
<br><font size=1 face="Courier New">boost::asio::ip::tcp::endpoint primaryEndpoint(boost::asio::ip::tcp::v4(),
primaryPort);</font>
<br><font size=1 face="Courier New">std::auto_ptr&lt;boost::asio::ip::tcp::acceptor&gt;
primaryAcceptor;</font>
<br>
<br><font size=1 face="Courier New">try</font>
<br><font size=1 face="Courier New">{</font>
<br><font size=1><tt>&nbsp; &nbsp; primaryAcceptor.reset(new boost::asio::ip::tcp::acceptor(ios,
primaryEndpoint));</tt></font>
<br><font size=1><tt>&nbsp; &nbsp; primaryAcceptor-&gt;open(primaryEndpoint.protocol());</tt></font>
<br><font size=1><tt>&nbsp; &nbsp; primaryAcceptor-&gt;set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));</tt></font>
<br><font size=1><tt>&nbsp; &nbsp; primaryAcceptor-&gt;bind(primaryEndpoint);</tt></font>
<br><font size=1 face="Courier New">}</font>
<br><font size=1 face="Courier New">catch(std::exception&amp; ex)</font>
<br><font size=1 face="Courier New">{</font>
<br><font size=1><tt>&nbsp; &nbsp; std::cout &lt;&lt; &quot;Error: Cannot
obtain port &quot; &lt;&lt; primaryPort </tt></font>
<br><font size=1><tt>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;&lt; &quot;, &quot; &lt;&lt; ex.what()
&lt;&lt; &quot;, server must be already running.&quot; &lt;&lt; std::endl;</tt></font>
<br><font size=1 face="Courier New">}</font>
<br>
<br><font size=2 face="sans-serif">It always prints the error. The error
is 'Already open'. The exception gets thrown from the call to open. What
am I doing wrong please? If don't do the open etc then I can run up a second
instance and it will have the port also. It is as if SO_REUSEADDR is true.
I always thought that SO_REUSEADDR was false by default. When I run it
in the debugger and breakpoint before the call to open , the process has
the port open for listening, as revealed by 'netstat -a'. &nbsp;It is as
if it has already done the open with SO_REUSEADDR set to true.</font>
<br>
<br><font size=2 face="sans-serif">I am using boost version 1.42.0 on Windoze-XP
compiled with Visual Studio 2005 (don't laugh....).</font>
<br>
<br><font size=2 face="sans-serif">Regards,<br>
<br>
Andrew Marlow<br>
</font><font face="monospace"><br>
___________________________________________________________<br>
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is prohibited.<br>
<br>
Please refer to http://www.bnpparibas.co.uk/en/information/legal_information.asp?Code=ECAS-845C5H&nbsp; for additional disclosures.</font>