Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stops working after a while (probably user error) #2

Closed
kfatehi opened this issue Aug 17, 2015 · 7 comments
Closed

Stops working after a while (probably user error) #2

kfatehi opened this issue Aug 17, 2015 · 7 comments

Comments

@kfatehi
Copy link
Contributor

kfatehi commented Aug 17, 2015

Hi Willem,

Thanks for making Diont!

I have an issue and some questions about how this all works and how to use it correctly.

I'm announcing from a node process and listening from a cordova app, using your packages for both sides.

I was hoping you could shed some light on the proper way to use this for continued, long-term use.

Diont is working great although it seems that after some time, my cordova client no longer sees my node process's announcements.

  1. Should I be periodically re-announcing ? I've tried both approaches, and not sure which is yielding better results at this time.
  2. Is there some sort of "reset" (I don't mean renouncement. I've tried that too. See next for better phrasing)?
  3. Why is it that if I announce, the cordova client can keep on seeing it?
  4. Is diont continually announcing or keeping some sort of registry?
    5 How does this all even work, conceptually?

Unforunately I've not studied UDP nearly enough to grok this from your code -- it seems like black magic to me that it's even working.

Thanks very much in advance--I hope you've the time to respond.

@kfatehi
Copy link
Contributor Author

kfatehi commented Aug 17, 2015

I should also mention that if I simply kill and restart the node.js app, the cordova app sees the announcement.

@willemmulder
Copy link
Owner

Hi @keyvanfatehi thanks for being interested :-) Let's see if I can shine some light in the black box by giving a general description.

First off, let me say that Diont on Cordova works exactly the same as on NodeJS. So everything I write below, is valid for both.

Let's start with requiring and calling Diont, like this:

var diont = require('diont')();

Once Diont is called, it will check whether it has access to the proper UDP port on the network, and if so it will send a 'query' request to the network (not to a specific machine, but to the network in general; a broadcast so to say) to ask if there is any servers that have announced services. If a Diont server has an announced service, it will respond to the query message by re-announcing all its services to the network: that means sending a single UDP message to the network with all the information about the announced service in it. If a server has no announced services, it will ignore the query request and do nothing.

To summarize this part: on 'startup', Diont will actively query the network for services, and the Diont servers on the network respond with their announced services.

Next, we can announce a service ourselves. If we do that, two things happen:

  1. the service is actively announced on the network through one single UDP message (it's not automatically re-announced many times, through a timer or otherwise. It's just one single message, once)
  2. the service is added to the register of 'services'. If a 'query' message comes in (see above), the server will respond by re-announcing all the services in this register.

When renouncing a service, the opposite happens:

  1. the service is actively renounced on the network through one single UDP message (it's not automatically re-announced many times, through a timer or otherwise. It's just one single message, once)
  2. the service is removed from the register of 'services'. If a 'query' message comes in (see above), the server will not re-announce the specific service anymore.

If you have a flaky network and you want to make sure that you have all the service announcments that are available on the network, you could periodically run

diont.queryForServices();

And the servers that have announced services should re-announce their services.

Does that make sense?

@willemmulder
Copy link
Owner

That being said, if you are announcing new services from Diont A, and suddenly they don't arrive on the other Diont instances (say B and C), that means that either A or B and C have no access to the network anymore, or there is some other network issue going on, preventing messages to arrive at the proper places.

Are you announcing the messages from Cordova or from NodeJS?

@kfatehi
Copy link
Contributor Author

kfatehi commented Aug 18, 2015

@willemmulder That was a great explanation, it's completely clear now -- thank you very much! To answer your question I am announcing from Node.js.

I will mark this as closed. It seems that my original issue was due to my network, my incorrect use of diont in Cordova, my ignorance about how it worked, and the not knowing that I can simply call queryForServices again. Instead of calling that method I was messing with the Node.js server which was the wrong approach. I know better now thanks to your explanation!

@kfatehi kfatehi closed this as completed Aug 18, 2015
@willemmulder
Copy link
Owner

Haha, no problem. If you could add a line or two about the .queryForServices method somewhere in the readme, I'll gladly accept it; might be useful for others to know as well: I forgot to mention it there!

@kfatehi
Copy link
Contributor Author

kfatehi commented Aug 20, 2015

Hi Willem

I plan to extend the documentation a bit, but I want to think about it a
little bit more and practice using it a bit more in my app. You will see a
PR soon. Thanks again

On Tue, Aug 18, 2015 at 12:23 PM, Willem Mulder notifications@github.com
wrote:

Haha, no problem. If you could add a line or two about the
.queryForServices method somewhere in the readme, I'll gladly accept it;
might be useful for others to know as well: I forgot to mention it there!


Reply to this email directly or view it on GitHub
#2 (comment).

@willemmulder
Copy link
Owner

Perfect, thanks a lot Keyvan!

Looking forward to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants