Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] how to solve the network latency when opening the app

Hi Peiyuan,
 
Looks like you're never going to get to the "fail to connect"  logic below:
 
boolean result = client.isConnected();
if (!client.isConnected()==result)
 
You're effectively doing this:
 
if (!client.isConnected()==client.isConnected())
 
which means that it will always try to connect, regardless of if it is already connected.
 
if (!client.isConnected()) should work.
 
 
It also looks like you're not using the Paho Android Service, whilst not strictly required, it's very useful as it does a lot of the more complicated work for you. I'd recommend taking a look at the Sample app that's been written to see how best to use the Service.
 
Kind regards,
 
James Sutton
Software Engineer - IoT Foundation - MQTT Open Source Projects
Technical Trojan - Wimbledon Project

Phone: 01962 815438 | Extension: x372454
E-mail: james.sutton@xxxxxxxxxx
Personal Website: www.jsutton.co.uk
Find me on:      
IBM

Hursley Park
HursleySO212JN
United Kingdom
 
IBM United Kingdom Limited Registered in England and Wales with number 741598 Registered office: PO Box 41, North Harbour, Portsmouth, Hants. PO6 3AU
 
 
----- Original message -----
From: fang peiyuan <fang_peiyuan@xxxxxxxxx>
Sent by: paho-dev-bounces@xxxxxxxxxxx
To: "paho-dev@xxxxxxxxxxx" <paho-dev@xxxxxxxxxxx>
Cc:
Subject: [paho-dev] how to solve the network latency when opening the app
Date: Sat, Oct 17, 2015 3:39 AM
 
hi sir / mdm
 
this is peiyuan, i worte a MQTT programming using andriod, during my testing
 
i found out that whenever i turn on my 3G network the starting up of the app took a very long time
 
but however when i turn off the 3G and wifi network, after clicking the button it turn on automatically 
 
when i integrate this coding with my another programing that i wrote i face this issue.
 
May i known how to solve this problem
 
Currently i am using eclipse java client and andriod serice
 
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.roti.mqtt" >
    <uses-permission android:name="android.permission.WAKE_LOCK"/>

    <uses-permission android:name="android.permission.INTERNET"/>

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >
        <!-- Mqtt Service -->
        <service android:name="org.eclipse.paho.android.service.MqttService"> </service>
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest> public void buttonOnclick (View v)
    {
        try {

            client = new MqttClient(TCPaddress, clientid);

            boolean result = client.isConnected();



            if (!client.isConnected()==result)
            {
                System.out.println("fail to connect");
                Toast toast = Toast.makeText(null,"fail",Toast.LENGTH_LONG);
                toast.show();



            }
            else
            {
                client.connect();
                System.out.println("connect sucessful");
                Toast toast = Toast.makeText(null,"fail",Toast.LENGTH_LONG);
                toast.show();
            }


        }

        catch (Exception e)
        {
            e.printStackTrace();
        }

    }
}Kindly please advise me how to solve this issue thank you from peiyuan
 
 
 
 
 
_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/paho-dev
 


Back to the top