简体   繁体   中英

vysper address already in use

i would like to use the XMPP server "Apache Vysper" in a Java-project, so i copy this example-code:

public class Start {

    /**
     * 
     * @param args
     */
    public static void main(String[] args) throws AccountCreationException,
    EntityFormatException, FileNotFoundException {

        // choose the storage you want to use
        //StorageProviderRegistry providerRegistry = new JcrStorageProviderRegistry();
        StorageProviderRegistry providerRegistry = new MemoryStorageProviderRegistry();

        final AccountManagement accountManagement = (AccountManagement) providerRegistry
                .retrieve(AccountManagement.class);

        Entity user1 = EntityImpl.parse("user1@vysper.org");
        if (!accountManagement.verifyAccountExists(user1)) {
            accountManagement.addUser(user1, "password1");
        }
        Entity user2 = EntityImpl.parse("user2@vysper.org");
        if (!accountManagement.verifyAccountExists(user2)) {
            accountManagement.addUser(user2, "password1");
        }
        Entity user3 = EntityImpl.parse("user3@vysper.org");
        if (!accountManagement.verifyAccountExists(user3)) {
            accountManagement.addUser(user3, "password1");
        }


        XMPPServer server = new XMPPServer("vysper.org");

        server.addEndpoint(new TCPEndpoint());

        WebSocketEndpoint wsEndpoint = new WebSocketEndpoint() {

            // example of how you can combine Vysper with other resources 
            @Override
            protected Server createJettyServer() {
                Server jetty = super.createJettyServer();
                ResourceHandler resourceHandler = new ResourceHandler();
                resourceHandler.setResourceBase("src/examples/client");
                jetty.setHandler(resourceHandler);
                HandlerCollection handlers = new HandlerCollection();
                handlers.addHandler(resourceHandler);
                jetty.setHandler(handlers);

                return jetty;
            }
        };
        wsEndpoint.setContextPath("/ws");
        server.addEndpoint(wsEndpoint);

        server.setStorageProviderRegistry(providerRegistry);

        server.setTLSCertificateInfo(new File("src/cert/bogus_mina_tls.cert"),
        "boguspw");

        try {
            server.start();
            System.out.println("vysper server is running...");
        } catch (Exception e) {
            e.printStackTrace();
        }

        server.addModule(new SoftwareVersionModule());
        server.addModule(new EntityTimeModule());
        server.addModule(new VcardTempModule());
        server.addModule(new XmppPingModule());
        server.addModule(new PrivateDataModule());
    }
 }

But when i run the code, i get always a "java.net.BindException":

log4j:WARN No appenders could be found for logger (org.apache.vysper.xmpp.server.DefaultServerRuntimeContext).
log4j:WARN Please initialize the log4j system properly.
java.net.BindException: Die Adresse wird bereits verwendet
    at sun.nio.ch.Net.bind0(Native Method)
    at sun.nio.ch.Net.bind(Net.java:414)
    at sun.nio.ch.Net.bind(Net.java:406)
    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
    at org.apache.mina.transport.socket.nio.NioSocketAcceptor.open(NioSocketAcceptor.java:248)
    at org.apache.mina.transport.socket.nio.NioSocketAcceptor.open(NioSocketAcceptor.java:48)
    at org.apache.mina.core.polling.AbstractPollingIoAcceptor.registerHandles(AbstractPollingIoAcceptor.java:525)
    at org.apache.mina.core.polling.AbstractPollingIoAcceptor.access$200(AbstractPollingIoAcceptor.java:66)
    at org.apache.mina.core.polling.AbstractPollingIoAcceptor$Acceptor.run(AbstractPollingIoAcceptor.java:406)
    at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:64)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

i use linux.

what i am doing wrong? Thanks!

Based on your error I think the port is blocked. By default vysper uses the 5222 port. Check if your firewall or other app blocks this port.

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