java.net.BindException: Address already in use: bind


環境:jxse-2.7, netty-3.6.6.Final  

現象:每次執行都拋出以下異常

八月 08, 2013 8:45:19 下午 net.jxta.logging.Logging logCheckedInfo
INFO: Line 127 net.jxta.impl.endpoint.netty.NettyTransportServer.bindServerChannel()
Attempt to bind to /0.0.0.0:8080 failed (Address already in use: bind), trying another address
八月 08, 2013 8:45:19 下午 org.jboss.netty.channel.SimpleChannelUpstreamHandler
WARNING: EXCEPTION, please implement org.jboss.netty.channel.socket.httptunnel.TunnelWrappedServerChannelHandler.exceptionCaught() for proper handling.
java.net.BindException: Address already in use: bind
    at sun.nio.ch.Net.bind0(Native Method)
    at sun.nio.ch.Net.bind(Net.java:444)
    at sun.nio.ch.Net.bind(Net.java:444)
    at sun.nio.ch.Net.bind(Net.java:436)
    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
    at org.jboss.netty.channel.socket.nio.NioServerBoss$RegisterTask.run(NioServerBoss.java:193)
    at org.jboss.netty.channel.socket.nio.AbstractNioSelector.processTaskQueue(AbstractNioSelector.java:366)
    at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:290)
    at org.jboss.netty.channel.socket.nio.NioServerBoss.run(NioServerBoss.java:42)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)

——————————————————————————————————————————————————————————————————

注意到黃色背景文字,顯然8080端口被占用了;才想起最近安裝Oracle Database 11g Express Edition,在安裝時必須占用8080端口且無法修改。

停止Oracle服務,或按照《http://www.cnblogs.com/cuizhf/p/3246654.html》修改其端口。

上面的異常也說明Jxta綁定了8080端口(Why?),下面是NettyTransportServer初始化時的代碼:

    private void initServer(TCPAdv instanceConfiguration) throws PeerGroupException {
        
        this.serverEnabled = instanceConfiguration.isServerEnabled();

        if(!serverEnabled) {
            this.server = new NullTransportServerComponent();
            return;
        }
        
        String interfaceAddress = instanceConfiguration.getInterfaceAddress();
        
        InetAddress bindAddr;
        if(interfaceAddress != null) {
            bindAddr = TransportUtils.resolveInterfaceAddress(interfaceAddress);
        } else {
            bindAddr = IPUtils.ANYADDRESS;
        }
        
        String publicName = instanceConfiguration.getServer();
        EndpointAddress publicAddress = null;
        if (publicName != null) {
            publicAddress = new EndpointAddress(protocolName, publicName, null, null);
        }
        
        NettyTransportServer server = new NettyTransportServer(createServerSocketChannelFactory(), new InetSocketAddressTranslator(protocolName), group);
        
        int preferredPort = correctPort(instanceConfiguration.getPort(), 1, 65535, getDefaultPort(), getDefaultPort(), "Preferred");
        int startPort = correctPort(instanceConfiguration.getStartPort(), 1, preferredPort, getDefaultPortRangeLowerBound(), 1, "Range start");
        int endPort = correctPort(instanceConfiguration.getEndPort(), startPort, 65535, getDefaultPortRangeUpperBound(), 65535, "Range end");
        List<InetSocketAddress> potentialBindpoints = IPUtils.createRandomSocketAddressList(bindAddr, preferredPort, startPort, endPort);
        
        server.init(potentialBindpoints, publicAddress, instanceConfiguration.getPublicAddressOnly());
        this.server = server;
    }

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM