[ 
https://issues.apache.org/jira/browse/FTPSERVER-292?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12700120#action_12700120
 ] 

Francis De Brabandere edited comment on FTPSERVER-292 at 4/17/09 3:53 AM:
--------------------------------------------------------------------------

temporary solution: add this code just before starting up your server

{code}
        /**
         * Throws an exception if we can connect to the port.
         * There is a problem on windows that makes two servers can be started 
on the same port:
         * 
http://www.mail-archive.com/[email protected]/msg00749.html
         * @throws FtpException
         */
        private void checkForOtherServer(final int port) throws FtpException{
                Socket sock = null;
                try {
                        sock = new Socket();
                        sock.bind(null);
                        sock.connect(new InetSocketAddress("localhost", port), 
200);
                        throw new FtpException("An other server is running on 
port "+port);
                } catch (UnknownHostException e) {
                        throw new FtpException(e.getMessage(), e);
                } catch (IOException e) {
                        logger.debug("No other server running.");
                } finally {
                        if(sock != null){
                                try {
                                        sock.close();
                                } catch (IOException e) {
                                        logger.warn("Could not close test 
socket");
                                }
                        }
                }
        }


      was (Author: francisdb):
    temporary solution: add this code just before starting up your server
[<pre>
        /**
         * Throws an exception if we can connect to the port.
         * There is a problem on windows that makes two servers can be started 
on the same port:
         * 
http://www.mail-archive.com/[email protected]/msg00749.html
         * @throws FtpException
         */
        private void checkForOtherServer(final int port) throws FtpException{
                Socket sock = null;
                try {
                        sock = new Socket();
                        sock.bind(null);
                        sock.connect(new InetSocketAddress("localhost", port), 
200);
                        throw new FtpException("An other server is running on 
port "+port);
                } catch (UnknownHostException e) {
                        throw new FtpException(e.getMessage(), e);
                } catch (IOException e) {
                        logger.debug("No other server running.");
                } finally {
                        if(sock != null){
                                try {
                                        sock.close();
                                } catch (IOException e) {
                                        logger.warn("Could not close test 
socket");
                                }
                        }
                }
        }
</pre>
  
> Starting two servers on the same port should fail
> -------------------------------------------------
>
>                 Key: FTPSERVER-292
>                 URL: https://issues.apache.org/jira/browse/FTPSERVER-292
>             Project: FtpServer
>          Issue Type: Improvement
>         Environment: windows xp
>            Reporter: Francis De Brabandere
>
> see this thread:
> http://www.mail-archive.com/[email protected]/msg00749.html
> I start up a ftp server in my unit tests. But I want to make sure
> there is only one instance running on a port, starting a second server
> on the same port should fail (throw an exception).
> Right now the second server starts up without errors but making a
> connection to the port used gives me the first server...
> =quote=
> Windows has a weird (or wrong)
> treatment of SO_REUSEADDR. You can read more about it here:
> http://msdn.microsoft.com/en-us/library/ms740621(VS.85).aspx
> This has been discussed here before, but with no good resolution. One
> possibility is that we could make our use of SO_REUSEADDR
> configurable.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to