1

Java プロジェクトで XMPP サーバー「Apache Vysper」を使用したいので、このサンプル コードをコピーします。

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());
    }
 }

しかし、コードを実行すると、常に「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)

私はLinuxを使用しています。

私は何を間違っていますか?ありがとう!

4

1 に答える 1