gpt4 book ai didi

java - vysper 地址已被使用

转载 作者:太空宇宙 更新时间:2023-11-04 14:34:38 25 4
gpt4 key购买 nike

我想在 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。

我做错了什么?谢谢!

最佳答案

根据您的错误,我认为该端口已被阻止。默认情况下,vysper 使用 5222 端口。检查您的防火墙或其他应用程序是否阻止此端口。

关于java - vysper 地址已被使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25742217/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com