Smack API 和 Java
我正在使用 Tapestry 5、Smack api 3.1.0。
我已经建立了连接,并且能够通过 xmpp 服务器与用户进行通信,但我收到的回复会在进入时发送到标准输出:
Chat chat = connection.getChatManager().createChat("[email protected]", new MessageListener() {
public void processMessage(Chat chat, Message message) {
// Print out any messages we get back to standard out.
System.out.println("Received message: " + message.getBody()); // this works
showonbrowser = message.getBody();
System.out.println(showonbrowser) // this prints nothing
}
};
我希望获得对我的 html 文件的回复,以便我可以阅读它们网络而不是控制台。 但是,当我尝试将 message.getBody() 设置为 showonbrowser (页面上的属性)时,我看不到任何结果。 有谁知道我如何解决这个问题?
问候,
凯斯
I am using Tapestry 5, Smack api 3.1.0.
I have established a connection and am able to communicate with a user through the xmpp server but the replies i get are sent to the standard output as they come in:
Chat chat = connection.getChatManager().createChat("[email protected]", new MessageListener() {
public void processMessage(Chat chat, Message message) {
// Print out any messages we get back to standard out.
System.out.println("Received message: " + message.getBody()); // this works
showonbrowser = message.getBody();
System.out.println(showonbrowser) // this prints nothing
}
};
I am looking to get the replies to my html file so i can read them on the web instead of the console. However, when i try to set message.getBody() to showonbrowser (a property on the page) i see no result. Does anyone know how I get around this?
Regards,
Kace
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Smack 是多线程的,它有一个讨厌的习惯,会(默默地)吃掉抛出的异常。很可能您没有使用线程安全的 GUI,并且它会抛出一个您永远不会得到的异常。
Smack is multi-threading and it has a nasty habit of eating up exceptions that are thrown (silently.) Most likely you are not using a thread-safe GUI and its throwing an exception that you never get.
我认为
processMessage
方法是在页面呈现之后被调用的。您正在创建一个 MessageListener 实例(通过匿名类),因此您不知道何时会调用 processMessage 方法。 我认为您必须使用 AJAX 做一些事情来在页面上进行部分更新,轮询服务器并获取任何新消息以将其显示在页面上。
I think the
processMessage
method is being called after the page is rendered.You are creating a MessageListener instance (through an anonymous class), so you don't know when the processMessage method will be called. I think you would have to do something with AJAX to do partial updates on the page, polling the server and getting any new messages to show them on the page.