没有得到smack的离线消息

时间:2017-12-17 19:01:44

标签: android xmpp openfire smack

我正在尝试使用openfire,smack和android的聊天应用程序,其中脱机消息不起作用。如果两个用户都在线,则能够正确地发送和接收消息。但是,如果用户A处于离线状态而用户B发送了一条消息,则用户A一旦在线就没有收到B的已发送消息。来自stackoverflow的可能解决方案但没有一个正常工作。使用以下代码检索脱机消息。

new Thread(){             public void run(){

from pyChrome import PyChrome
>>> link = "http://www.destinylfg.net/"
>>> from pyChrome import PyChrome
>>> browser = PyChrome()

DevTools listening on ws://127.0.0.1:12483/devtools/browser/7b01bebd-7cb7-475b-ba8f-6e3b29ca4d9a
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pyChrome.py", line 96, in __init__
    self.__start(ghostmode=self.ghost)
  File "pyChrome.py", line 192, in __start
    self.window = Window(self.driver, config_filename=self.config_filename)
  File "C:\Users\James\Desktop\pyChrome/src\window.py", line 78, in __init__
   self.__readJSONFile()
  File "C:\Users\James\Desktop\pyChrome/src\window.py", line 63, in__readJSONFile
if self.validateScroll(scrollWin):
  File "C:\Users\James\Desktop\pyChrome/src\window.py", line 335, in validateScroll
scrollHeight = self.driver.execute_script("returndocument.body.scrollHeight")
  File "C:\Python27\lib\site-packages\selenium-3.8.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 546, in execute_script
'args': converted_args})['value']
  File "C:\Python27\lib\site-packages\selenium-3.8.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 309, in execute
response = self.command_executor.execute(driver_command, params)
  File "C:\Python27\lib\site-packages\selenium-3.8.0-py2.7.egg\selenium\webdriver\remote\remote_connection.py", line 460, in execute
return self._request(command_info[0], url, body=data)
  File "C:\Python27\lib\site-packages\selenium-3.8.0-py2.7.egg\selenium\webdriver\remote\remote_connection.py", line 484, in _request
resp = self._conn.getresponse()
  File "C:\Python27\lib\httplib.py", line 1121, in getresponse
response.begin()
  File "C:\Python27\lib\httplib.py", line 438, in begin
version, status, reason = self._read_status()
  File "C:\Python27\lib\httplib.py", line 394, in _read_status
line = self.fp.readline(_MAXLINE + 1)
  File "C:\Python27\lib\socket.py", line 480, in readline
data = self._sock.recv(self._rbufsize)
 socket.error: [Errno 10054] An existing connection was forcibly closed by the         
 remote host
>>> [5272:7832:1217/135245.823:ERROR:service_manager.cc(157)] Connection InterfaceProviderSpec prevented service: content_renderer from binding interface: blink::mojom::ReportingServiceProxy exposed by: content_browser

1 个答案:

答案 0 :(得分:0)

经过多次斗争,我已经解决了这个问题。在您的openfire管理页面中,转到&#34;客户端设置&#34;并将空闲时间从360秒(默认情况下)减少到1秒(可能)。只有当您与Internet断开连接时,它才会检测到您处于脱机状态并将其余消息保留为OFFLINE。

@Override public void onNetworkConnectionChanged(boolean isConnected){

if(isConnected){
    new Thread() {

        public void run() {
            try {
                XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();
                builder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
                builder.setUsernameAndPassword("phone", "admin");
                builder.setSendPresence(true);
                builder.setServiceName(<Service name>);
                builder.setHost(<Host name>);
                builder.setResource("Test");
                builder.setDebuggerEnabled(true);
                Presence presence = new Presence(Presence.Type.available);
                presence.setStatus("Available");
                connection = new XMPPTCPConnection(builder.build());
                connection.connect();
                connection.login();
                Presence presence123 = new Presence(Presence.Type.available);
                presence123.setStatus("Available");
                try {
                    connection.sendStanza(presence123);
                } catch (SmackException.NotConnectedException e) {
                    e.printStackTrace();
                }
                StanzaFilter filter = new AndFilter(new StanzaTypeFilter(Message.class));
                PacketListener myListener = new PacketListener()
                {
                    public void processPacket(Stanza stanza)
                    {
                        retrieveMessage(stanza,userType);
                    }
                };
                connection.addPacketListener(myListener, filter);
                try {
                    connection.sendStanza(presence);
                } catch (SmackException.NotConnectedException e) {
                    e.printStackTrace();
                }

            } catch (SmackException | XMPPException | IOException e) {
                e.printStackTrace();
            }


            //return connection.isConnected();
        }

    }.start(); 

以上工作正常,能够检索离线消息。方法&#34; retrieveMessage(节,用户类型);&#34;用于处理传入的消息并更新适配器。确保将状态发送为&#34;可用&#34;当你重新连接。如果还有任何问题,请告诉我。

相关问题