问题描述
这个问题是我之前关于这个问题""
This question is Extension of my previous question on this SO question "How to connect XMPP bosh server using java smack library?"
我正在使用Java作为服务器端语言.感谢@Deuteu,我已成功使用smach-jbosh实现xmpp BOSH连接,感谢@Deuteu帮助我实现了这一点,到目前为止,我已经修改了jbosh的 BOSHClient.java
文件,并添加了两个getter方法来提取RID和SID.
I am using Java as server side language. I have successfully implement xmpp BOSH connection using smach-jbosh thanks to @Deuteu for helping me to achieve this, so far I have modify jbosh's BOSHClient.java
file and added two getter method for extracting RID and SID.
现在我的应用程序服务器上有RID和SID(我正在使用Apache Tomcat).我需要将此凭据传递给Strophe(Web客户端),以便它可以连接到连接.
Now I have RID and SID on my app server (I am using Apache Tomcat). I need to pass this credential to Strophe (web client) so that it can attach to connection.
在这里,我有些怀疑.
- 何时断开Bosh Connection建立与应用程序服务器的连接?在将sid,rid和jid传递给strophe之前还是在通过sid,rid和jid传递给strophe之后?根据我在实施过程中的观察,我观察到一旦断开与应用服务器的bosh连接,会话将过期,并且SID和RID不再有用!!!
- 我已经在Servlet上实现了此逻辑(建立bosh连接并提取sid和rid),在此,一旦从Servlet发送了响应,线程将过期,而结束的BOSH连接将终止,因此我无法执行`会话终止时,在续航时使用Attach()`.
- When to disconnect bosh Connection establish from the app server? before passing sid, rid and jid to strophe or after passing sid, rid and jid to strophe?
As per my observation during implementation for the same, I have observed that once bosh connection from the app server has been disconnected, session is expired and SID and RID is no longer useful!!! - I have implemented this logic (Establishing bosh connection and Extracting sid and rid) on a Servlet, here once response has been send from Servlet, Thread will get expired and end BOSH connection will get terminated, so I am not able perform `Attach()` on strophe as session is expired.
有人可以帮助我解决这个问题吗?
Can somebody help me with that problem?
推荐答案
使用smack创建BOSH会话并提取SID + RID值后,需要将它们传递给Strophe的attach(),然后从此处开始您需要让strophe处理这种连接.连接Strophe之后,您根本不希望服务器对连接进行任何操作.
After you have created a BOSH session with smack and have extracted the SID+RID values, you need to pass them to Strophe's attach() and from here on out you need to let strophe deal with this connection. Once Strophe has attached, you do not want your server to be doing anything to the connection at all.
如果在附加了strophe后您的服务器端代码根本没有向连接管理器发送任何消息,则很可能它将发送一个无效的RID,这将导致您的会话终止.
If your server side code sends any messages at all to the connection manager after strophe has attached, it's likely that it will send a invalid RID which will cause your session to terminate.
同样,一旦建立了会话并可以使用它,就不要尝试从服务器端继续使用它.在服务器端bosh客户端完成身份验证并将SID + RID传递到页面之后,只需销毁服务器端连接对象,不要尝试断开连接或进行任何其他操作,因为这将结束会话.
Again, once the session has been established and is usable by strophe, do not attempt to continue using it from the server side. After your server side bosh client completes authentication and you've passed the SID+RID to the page, just destroy the server side connection object, don't attempt to disconnect or anything as this will end your session.
您需要记住的是,与基于TCP的传统XMPP连接不同,BOSH客户端不维护与服务器的持久连接(这就是为什么我们在Web应用程序中使用BOSH的原因).因此,没有什么可以断开的.持久连接实际上是XMPP服务器和BOSH连接管理器之间的连接,您无需处理.因此,当您从服务器端BOSH客户端调用断开连接时,您是在告诉连接管理器结束会话并关闭其与XMPP服务器的连接,这完全破坏了首先创建会话的目的.
The thing you need to remember is, unlike traditional XMPP connections over TCP, BOSH clients do NOT maintain a persistent connection to the server (this is why we use BOSH in web applications). So there is nothing to disconnect. The persistent connection is actually between the XMPP server and the BOSH connection manager, it's not something you need to deal with. So when you call disconnect from your server side BOSH client, you're telling the connection manager to end the session and close it's connection to the XMPP server, which completely defeats the purpose of creating the session in the first place.
这篇关于何时断开Bosh连接从App Server建立以使用预绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!