You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ftpserver-users@mina.apache.org by Francis De Brabandere <fr...@gmail.com> on 2009/04/17 11:37:12 UTC
Making sure only one instance runs on a port
Hi,
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...
Thanks,
Francis
--
http://www.somatik.be
Microsoft gives you windows, Linux gives you the whole house.
Re: Making sure only one instance runs on a port
Posted by Francis De Brabandere <fr...@gmail.com>.
https://issues.apache.org/jira/browse/FTPSERVER-292
On Fri, Apr 17, 2009 at 12:38 PM, Niklas Gustavsson
<ni...@protocol7.com> wrote:
> Yeah, that should work. Feel free to open a JIRA issue for improving
> this by making our use of SO_REUSEADDR configurable.
>
> /niklas
>
> On Fri, Apr 17, 2009 at 12:02 PM, Francis De Brabandere
> <fr...@gmail.com> wrote:
>> yep we're working on windows XP, thanks for the link
>>
>> this is what i'm doing right now... ugly but it works
>>
>> /**
>> * Throws an exception if we can connect to the port
>> * @throws FtpException
>> */
>> private void checkForOtherServer(final int port) throws FtpException{
>> try {
>> Socket sock = new Socket("localhost", port);
>> sock.close();
>> 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.");
>> }
>> }
>>
>> On Fri, Apr 17, 2009 at 11:48 AM, Niklas Gustavsson
>> <ni...@protocol7.com> wrote:
>>> On Fri, Apr 17, 2009 at 11:37 AM, Francis De Brabandere
>>> <fr...@gmail.com> wrote:
>>>> 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...
>>>
>>> I'm guessing this is on WIndows? 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.
>>>
>>> /niklas
>>>
>>
>>
>>
>> --
>> http://www.somatik.be
>> Microsoft gives you windows, Linux gives you the whole house.
>>
>
--
http://www.somatik.be
Microsoft gives you windows, Linux gives you the whole house.
Re: Making sure only one instance runs on a port
Posted by Niklas Gustavsson <ni...@protocol7.com>.
Yeah, that should work. Feel free to open a JIRA issue for improving
this by making our use of SO_REUSEADDR configurable.
/niklas
On Fri, Apr 17, 2009 at 12:02 PM, Francis De Brabandere
<fr...@gmail.com> wrote:
> yep we're working on windows XP, thanks for the link
>
> this is what i'm doing right now... ugly but it works
>
> /**
> * Throws an exception if we can connect to the port
> * @throws FtpException
> */
> private void checkForOtherServer(final int port) throws FtpException{
> try {
> Socket sock = new Socket("localhost", port);
> sock.close();
> 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.");
> }
> }
>
> On Fri, Apr 17, 2009 at 11:48 AM, Niklas Gustavsson
> <ni...@protocol7.com> wrote:
>> On Fri, Apr 17, 2009 at 11:37 AM, Francis De Brabandere
>> <fr...@gmail.com> wrote:
>>> 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...
>>
>> I'm guessing this is on WIndows? 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.
>>
>> /niklas
>>
>
>
>
> --
> http://www.somatik.be
> Microsoft gives you windows, Linux gives you the whole house.
>
Re: Making sure only one instance runs on a port
Posted by Francis De Brabandere <fr...@gmail.com>.
yep we're working on windows XP, thanks for the link
this is what i'm doing right now... ugly but it works
/**
* Throws an exception if we can connect to the port
* @throws FtpException
*/
private void checkForOtherServer(final int port) throws FtpException{
try {
Socket sock = new Socket("localhost", port);
sock.close();
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.");
}
}
On Fri, Apr 17, 2009 at 11:48 AM, Niklas Gustavsson
<ni...@protocol7.com> wrote:
> On Fri, Apr 17, 2009 at 11:37 AM, Francis De Brabandere
> <fr...@gmail.com> wrote:
>> 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...
>
> I'm guessing this is on WIndows? 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.
>
> /niklas
>
--
http://www.somatik.be
Microsoft gives you windows, Linux gives you the whole house.
Re: Making sure only one instance runs on a port
Posted by Niklas Gustavsson <ni...@protocol7.com>.
On Fri, Apr 17, 2009 at 11:37 AM, Francis De Brabandere
<fr...@gmail.com> wrote:
> 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...
I'm guessing this is on WIndows? 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.
/niklas