mina-ftpserver-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Albert Visagie (External)" <alb...@vastech.co.za>
Subject Re: check if address already in use
Date Thu, 10 Jun 2010 06:00:23 GMT
Niklas Gustavsson wrote:
> On Wed, Jun 9, 2010 at 3:03 PM, Albert Visagie <albert@vastech.co.za> wrote:
>   
>>> The following simple program, successfully serves up an ftp site. If
>>> started again, it logs that the FtpServer has started. My eclipse debugger
>>> shows that the acceptor thread has started. The first one still works, as
>>> expected. The second just sits there forever.
>>>       
>
> What OS is this on? I just ran the code on OS X and the second process
> outputs the following and then exits:
>   

In my case it was on Windows Vista x64, running a recent 32bit java 1.6.

Linux also responds "correctly".  :)

Out of curiosity, I made the following little test program. It seems to 
demonstrate the difference in behaviour on Windows and Linux.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.UnknownHostException;

public class Reuse {
    private static void bind() throws UnknownHostException, IOException {
        Thread th = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    ServerSocket s = new ServerSocket();
                    s.setReuseAddress(true);
                    s.bind(new 
InetSocketAddress(InetAddress.getLocalHost(), 12347));
                    s.accept();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });
        th.setDaemon(true);
        th.start();
    }

    public static void main(String[] args) throws Exception {
        bind();
        Thread.sleep(1000);
        bind();
        System.out.println("bound. Press Enter.");
        new BufferedReader(new InputStreamReader(System.in)).readLine();
    }
}



-- 
Albert Visagie



Mime
View raw message