Project

General

Profile

keepalive

Hic cup
Added almost 3 years ago

hi!

 Exception in worker
java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.socketRead(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at java.util.zip.InflaterInputStream.fill(Unknown Source)
    at java.util.zip.InflaterInputStream.read(Unknown Source)
    at tigase.jaxmpp.j2se.connectors.socket.TextStreamReader.read(TextStreamReader.java:49)
    at tigase.jaxmpp.j2se.connectors.socket.Worker.run(Worker.java:99)

Method keepalive() in SocketConnector.java just send "new byte[] { 32 }" to server,but the server response nothing.

Should I send ping to keep alive instead of "new byte[] { 32 }" ?

thinks!


Replies (6)

(1)

Added by Wojciech Kapcia TigaseTeam almost 3 years ago

This is whitespace ping and it's described in RFC1620 - Dead Connection No, server don't have to respond to it. If you require more resilience you can utilize XEP-0199: XMPP Ping which is also supported in JaXMPP and Tigase server.

(1)

Added by Hic cup almost 3 years ago

thinks for reply!

"Read timed out" Exception occurred if only use "jaxmpp.keepalive()".

I guess it caused by noting response.... then socket timeout.

should i ignore this ?

Added by Wojciech Kapcia TigaseTeam almost 3 years ago

What are you trying to do exactly???

This is simple keepalive packet to keep the connection open, it doesn't require the response and stacktrace provided by you doesn't match any current branch from Jaxmpp library.

In addition - jaxmpp.keepalive() will be called periodically when needed and there's no need to call it manually.

Added by Hic cup almost 3 years ago

My test file:

public static void main(String[] args) throws JaxmppException, InterruptedException {
        final Jaxmpp jaxmpp = new Jaxmpp();

        jaxmpp.getProperties().setUserProperty(SocketConnector.SERVER_HOST, "192.168.1.100");
        jaxmpp.getProperties().setUserProperty(SessionObject.USER_BARE_JID, BareJID.bareJIDInstance("c1@xx.com"));
        jaxmpp.getProperties().setUserProperty(SessionObject.PASSWORD, "1");

        jaxmpp.getConnectionConfiguration().setDisableTLS(true);

        jaxmpp.getConnectionConfiguration().setPort(15222);

        jaxmpp.login();

        jaxmpp.keepalive();
        Presence.initialize(jaxmpp);
        PresenceModule presence=jaxmpp.getModulesManager().getModule(PresenceModule.class);
        presence.sendInitialPresence();

        MessageModule msgmodule = jaxmpp.getModulesManager().register(new MessageModule());

        jaxmpp.getEventBus().addHandler(MessageReceivedEvent.class, msgmodule, new MessageReceivedHandler() {

            @Override
            public void onMessageReceived(SessionObject sessionObject, Chat chat, Message stanza) {
                try {
                    System.out.println("-------MessageReceived-------" + stanza.getBody());
                } catch (XMLException e) {
                    e.printStackTrace();
                }
            }
        });


        Thread.sleep(10 * 60 * 1000);

        jaxmpp.disconnect();
    }

Just now I find the "jaxmpp.getConnectionConfiguration().setDisableTLS(true);" cause the Exception.

It works well since Comment this line, I will check the detail tomorrow.

think you very much!

Added by Wojciech Kapcia TigaseTeam almost 3 years ago

Bottomline - keepalive is enabled by default and you can disable it with Connector option: @Connector.DISABLE_KEEPALIVE_KEY@:

jaxmpp.getProperties().setUserProperty( SocketConnector.DISABLE_KEEPALIVE_KEY, Boolean.TRUE );

Executing it manually is not recommended. Also - it's possible connection is not yet fully established and checking if user is connected (@jaxmpp.isConnecte()@) is a good idea.

(1)

Added by Hic cup almost 3 years ago

i see, thinks!

    (1-6/6)