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

Making too many connections at server side #118

Closed musriabhijit closed 7 years ago

musriabhijit commented 8 years ago

in Onstart of every activity i am writing like this

if (MeteorSingleton.hasInstance()) { mMeteor = MeteorSingleton.getInstance(); } else { MeteorSingleton.createInstance(this, "my socket connection ", new InMemoryDatabase()); mMeteor = MeteorSingleton.getInstance(); }

    mMeteor.addCallback(this);
    mMeteor.connect();

and in onConnect method i am making the subscribe

but at server side they are telling that you are making too many server connections so some times i am able to connect and some times i am not able to connect so what i am doing is the correct one or not if i am wrong please correct me

ocram commented 8 years ago

Thanks for this question!

Can you try moving

mMeteor.addCallback(this);
mMeteor.connect();

from outside the condition into the else branch right before these lines, i.e. right after createInstance?

That should help because it will only establish a new connection when there was no singleton instance available, previously.

musriabhijit commented 8 years ago

if i use mMeteor.addCallback(this); mMeteor.connect(); in the else part the meteor is not calling onDataAdded , onConnect or onException in the the Activity class so can you guide me in this problem

ocram commented 8 years ago

You're right, sorry. Try moving only the mMeteor.connect(); call to the else branch as described before. The mMeteor.addCallback(this); call must be done from whatever Activity or Fragment you're trying to receive results in.

musriabhijit commented 7 years ago

if i use mMeteor.connect(); in else part it is same i am not able to call the onDataAdded, onConnect, onException so my question is if i use mMeteor.connect() it will create the new connection or not

ocram commented 7 years ago

Did you do this?

if (MeteorSingleton.hasInstance()) {
    mMeteor = MeteorSingleton.getInstance();
    mMeteor.addCallback(this);
}
else {
    MeteorSingleton.createInstance(this, "wss://example.com/websocket", new InMemoryDatabase());
    mMeteor = MeteorSingleton.getInstance();
    mMeteor.addCallback(this);
    mMeteor.connect();
}