delight-im / Android-DDP

[UNMAINTAINED] Meteor's Distributed Data Protocol (DDP) for clients on Android
Apache License 2.0
274 stars 54 forks source link

i cannot connect to server #136

Closed shankaranand007 closed 7 years ago

shankaranand007 commented 7 years ago

ConnectionDetector conDet = new ConnectionDetector(getBaseContext()); if(!conDet.isConnectingtoInternet()){ Toast.makeText(this, "NO..internet connection", Toast.LENGTH_SHORT).show(); }else{ Toast.makeText(this, "Internet connected", Toast.LENGTH_SHORT).show(); } //instance meteor = new Meteor(MainActivity.this, "ws://ydapp.in:3000//websocket"); //callback meteor.addCallback(this);

    //establish connection
     meteor.connect();

    if (meteor.isConnected()) {
        Toast.makeText(this, "connect", Toast.LENGTH_SHORT).show();
        Intent i = new Intent(MainActivity.this, Welcome.class);
        startActivity(i);
    } else {
        Log.e("Errorr","Error");
        Toast.makeText(this, "Not connect", Toast.LENGTH_SHORT).show();
        meteor.reconnect();
    }

This is my code i getting error from this i dont know

ocram commented 7 years ago

First, you should probably move lines 7 and the following (starting with the line // instance) from after the if/else to inside the else, right? It does not really make sense to execute this when you already know that there is no internet connection, does it?

Second, you should not attempt to detect the connection status right after calling connect. Instead, wait until you are notified in the onConnect callback from MeteorCallback.