NetTalk Central

Author Topic: Push Notification  (Read 9162 times)

Rhys Daniell

  • Newbie
  • *
  • Posts: 34
    • View Profile
Push Notification
« on: July 22, 2011, 07:07:27 PM »
At the moment we use a web service (NetTalk client/server) to poll a server for outbound messages, but as demand grows this is imposing too much load on the server.

Communication must be initiated by the client as our customers are not prepared to open an external port to allow the server to make contact. So we'd like to use push notification.

As I understand it this involves the client establishing a connection with the server which is then maintained (confirmed by an occasional ping).  When the server has a message for the client it notifies the client by sending a couple of bytes and then the client uses the web service to retrieve the message.

First question: Is there an option for a NetTalk server to keep the connection open?

Second question:  Presumably, for this to work with multiple clients, after the initial connection the connection would have to be moved to another port to leave the first port free for the next connection. Is this the case, and does NetTalk have this functionality?




Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11183
    • View Profile
Re: Push Notification
« Reply #1 on: July 22, 2011, 08:37:12 PM »
Hi Rhys,

To answer the first question - it's important to distinguish between a "webServer" and a "Server". Typically a connection between a server and a client remains open until either it is closed by one of the ends, or it is closed internally by a "inactive timeout".
A simple NetSimple server does have an inactiveTimeout property, whic you can adjust, but it doesn't close the connection unnecessarily.

A WebServer does close the connection at the end of a response - but isn't really for any particular reason other than the fact that it's easier to code that way.

>> Second question:  Presumably, for this to work with multiple clients, after the initial connection the connection would have to be moved to another port to leave the first port free for the next connection.

No, this is not correct. A single NetSimple server can handle multiple connections at the same time. It has a a queue of connections internally, and uses the self.packet.FromIP and self.packet.ToIp fields to let you know where a packet is from, and for you to specify where a packet you are sending should go to.

Cheers
Bruce

Rhys Daniell

  • Newbie
  • *
  • Posts: 34
    • View Profile
Re: Push Notification
« Reply #2 on: July 22, 2011, 08:46:57 PM »
Thanks Bruce,

This is probably too much to hope for, but can I have my 'push server' listen on port 80 on a PC which is also running a web server serving html?

TIA
Rhys

Rhys Daniell

  • Newbie
  • *
  • Posts: 34
    • View Profile
Re: Push Notification
« Reply #3 on: July 23, 2011, 12:07:13 AM »
Once I worked out I needed NetSimple and not NetAuto (d'oh!) I got a prototype together quickly, and so far it works wonderfully well. Another NetTalk win! Thanks Bruce.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11183
    • View Profile
Re: Push Notification
« Reply #4 on: July 24, 2011, 03:24:31 AM »
>> This is probably too much to hope for, but can I have my 'push server' listen on port 80 on a PC which is also running a web server serving html?

yes you can, but it's not completely trivial - and in fact it's probably _not_ what you want at all.

First why not - the problem with port 80 is that's is "special" - ie by convention used for the web, or put in technical terms by the HTTP protocol. So a lot of network equipment treats port 80 as special, and _expects_ the HTTP protocol to be used. Purely NetSimple based objects can actually have more trouble on Port 80 than on other ports.

So if Port 80 was a "definitely wanted" then I'd probably make my "NetSimple" protocol at least have an HTTP header on the client side, and a HTTP header on stuff coming from the server.

Now as far as sharing goes, you have a couple options.
First, can the machine have multiple IP addresses? If it can then simply put your web server on one IP address, and this class on the other.

If not, or you don't want to go that route, then you need to use the Multi-Site Host to "host" the web site, and also handle your NetSimple connections. That's do-able, but it would take a fair bit of effort to understand how the Host works, and to add code to support this configuration.

Cheers
Bruce




Rhys Daniell

  • Newbie
  • *
  • Posts: 34
    • View Profile
Re: Push Notification
« Reply #5 on: July 24, 2011, 04:19:05 PM »
Thanks again, Bruce!

I prefer the simple life, we'll choose another port and slug it out with the corporate sys admins.

Cheers
Rhys