简体   繁体   中英

Trying to start GrizzlyServer - failed to start listener - adress already in use

static HttpServer server;
static Datenbank  db = new Datenbank();

public static void main (String[] args) throws InterruptedException, IOException{

    startServer();
    db.dbinfo();
    Thread.sleep(10*60*1000);
    System.out.println("Server wurde beendet");
}

public static void startServer() throws IOException, InterruptedException {

    URI baseUri = UriBuilder.fromUri("http://localhost/").port(4434).build();

    ResourceConfig config = new ResourceConfig().register(BetroffenePersonenService.class);
    HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config);

    try{
        server.start();
        NetworkListener listener = new NetworkListener("grizzly2","localhost", 4434);
        server.addListener(listener);
    }
    catch (Exception e){
        System.err.println(e);

    }
      }
     }

I am trying to start this server but i keep getting this

16.01.2014 22:04:31 org.lightcouch.CouchDbClientBase process
INFO: >> HEAD /betroffene HTTP/1.1
16.01.2014 22:04:31 org.lightcouch.CouchDbClientBase process
INFO: << Status: 200
16.01.2014 22:04:31 org.glassfish.jersey.server.ApplicationHandler initialize
INFO: Initiating Jersey application, version Jersey: 2.5 2013-12-18 14:27:29...
16.01.2014 22:04:32 org.glassfish.grizzly.http.server.NetworkListener start
INFO: Started listener bound to [localhost:4434]
16.01.2014 22:04:32 org.glassfish.grizzly.http.server.HttpServer start
INFO: [HttpServer] Started.
16.01.2014 22:04:32 org.glassfish.grizzly.http.server.HttpServer addListener
SCHWERWIEGEND: Failed to start listener [NetworkListener{name='grizzly2',     host='localhost',       port=4434, secure=false, state=STOPPED}] : java.net.BindException:   Address already in use
16.01.2014 22:04:32 org.glassfish.grizzly.http.server.HttpServer addListener
SCHWERWIEGEND: java.net.BindException: Address already in use
 java.net.BindException: Address already in use
at sun.nio.ch.Net.bind(Native Method)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:124)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:59)
at org.glassfish.grizzly.nio.transport.TCPNIOBindingHandler.bindToChannelAndAddress(TCPNIOBindingHandler.java:132)
at org.glassfish.grizzly.nio.transport.TCPNIOBindingHandler.bind(TCPNIOBindingHandler.java:88)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.bind(TCPNIOTransport.java:233)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.bind(TCPNIOTransport.java:213)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.bind(TCPNIOTransport.java:204)
at org.glassfish.grizzly.http.server.NetworkListener.start(NetworkListener.java:680)
at org.glassfish.grizzly.http.server.HttpServer.addListener(HttpServer.java:171)
at server.AbleServer.startServer(AbleServer.java:39)
at server.AbleServer.main(AbleServer.java:23)

i have tried to find solutions online but i can not find any that work for me. I have restarted everything, but it still says, that the address is in use. it probably is a really small mistake that is causing all of this but it is really getting me frustrated. your help would be appreciated!

The server instance returned from

HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config);

had been already started, so you can remove these lines:

server.start();
NetworkListener listener = new NetworkListener("grizzly2","localhost", 4434);
server.addListener(listener);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM