0

I have a computer called Server and I have several computers called Nodes. The nodes are behind a NAT (router) and Server is not. In other words each node can connect to Server but Server cannot connect to a node.

In short I want to send a notification from Server to a Node

  • One solution would be to have multiple tcp connections open. But because there are multiple Nodes and the nodes stay connected forever I would prefer to use a different option.

  • Another solution is have each node make a request every 10 seconds or so. The problem is that when a notification occurs I will like for it to execute right away.

  • Another solution would be to port forward traffic on the router but some users do not have access to the router.

How should I implement this? I need to send a very simple notification and if a node receives that notification it will perform a specific action. Just out of curriosity take for instance Drop Box. The moment you modify a file it starts updating it right away on a differnt computer. How they do this? Do they use polling?

edit

This is what I believe will be the best solution:

Since the server is running my code and also the client. I will have the clients send UDP packets every 30 seconds. The server then can reply back and the NAT will enable traffic to pas. So whenever I want to notify a node I basically will have to send a packet. This solution is like inventing something new though. From experience every time you invent something new I have bad success. But it sounds like a good idea.

Tono Nam
  • 34,064
  • 78
  • 298
  • 470
  • Dropbox would use polling with their central server I guess. You can reduce your 10 seconds to 1, and get reasonable immediacy – Karthik T Nov 18 '13 at 02:42
  • 1
    Read about long polling: http://stackoverflow.com/questions/11077857/what-are-long-polling-websockets-server-sent-events-sse-and-comet – John Koerner Nov 18 '13 at 02:51
  • Yeah I guess that's what am I going to do. Long polling. What is the difference between having multiple connections open and doing long polling though? Performance wice... – Tono Nam Nov 18 '13 at 02:55

1 Answers1

1

Unfortunately that's not your invention. That's the way eMule has been using to connect to clients behind NAT. It works indeed. Just keep in mind that you can only use UDP in this way.

Meanwhile, if you want to make something quickly and reliable (maybe), why not try some 3rd party services like Service Bus of Windows Azure? Then you can focus on your logic, not the underlying details.

Gildor
  • 2,484
  • 23
  • 35