NetTalk Central

Author Topic: Web notification without sockets  (Read 4526 times)

Alberto

  • Hero Member
  • *****
  • Posts: 1873
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Web notification without sockets
« on: May 13, 2016, 04:18:02 AM »
Hi, knowing the limit of connectios using sockets, I began to investigate how Facebook does it, and its very simple.
FB sends a GET to the server, this GET is only responded if the server has anything to say to the client, if not the GET is not responded and stay Pendient.
The server keeps looping detecting something to respond to the client.

Any idea of how to implement this with NT?

I think NT server will start a thread for each client "connected" waiting to be notified.
Are there a limit here? a limit of how many trheads the server can start?
How does FB waits indefinetly with the pendient get without a time out?

Regards
-----------
Regards
Alberto

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Web notification without sockets
« Reply #1 on: May 15, 2016, 11:56:00 PM »
Hi Alberto,

>> knowing the limit of connectios using sockets .... FB sends a GET to the server, this GET is only responded if the server has anything to say to the client, if not the GET is not responded and stay pending...

But pending uses up a socket, so this approach gains you nothing over using a web socket.
(The technique is called "long polling" and predates web sockets by some time. It was a way to keep a connection open before web sockets existed.) The only reason you would use this technique now is if you had a client (browser) which did not support web sockets.

>> Any idea of how to implement this with NT?

Implementing this approach in NT would be really bad, because you would have a lot of work to do (the stuff the WebSockets is already doing under-the-hood) and you would "stall" a thread in the mean time. So you gain nothing, and lose a fair bit in the process.

cheers
Bruce

Alberto

  • Hero Member
  • *****
  • Posts: 1873
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Re: Web notification without sockets
« Reply #2 on: May 16, 2016, 03:33:49 AM »
Ok, understood, then it is not a big problem to deal with many sockets, suppouse a 1000 clients, what type of server and connection bandwidth do you need?
And how do I implementthis kind of job with sockets in NT8?
-The client opens a socket and inform the server what it needs.
-The server keeps this need till it has anything to send to the client (loop)
-The server sends something to the ckient which uses it (morely to refresh a browse) and inform the server its still alive and waiting for more.
Can it be done?

Please see gif attached, thats what I need to do...
« Last Edit: May 17, 2016, 02:53:56 AM by michelis »
-----------
Regards
Alberto

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Web notification without sockets
« Reply #3 on: May 17, 2016, 11:12:08 PM »
Hi Alberto,

>> Ok, understood, then it is not a big problem to deal with many sockets, suppose a 1000 clients,
>> what type of server and connection bandwidth do you need?

A typical Windows Server machine can do upwards of 20 000 sockets (maybe as many as 65000 sockets - I haven't been able to test that) so 1000 is no problem.

CPU requirements and bandwidth is completely dependent on what you are doing - how often you are sending data, how much data you are sending and so on. Usually I start small and monitor usage and increase as required.

>> And how do I implement this kind of job with sockets in NT8?

Sockets are in NT9, not NT8, so it would be a lot of work to implement sockets in NT8. (You'd basically have to write a web socket class, and that's not trivial to do.)

>>-The client opens a socket and inform the server what it needs.
>>-The server keeps this need till it has anything to send to the client (loop)
>>-The server sends something to the client which uses it (merely to refresh a browse) and inform the server its still alive and waiting for more.
>> Can it be done?

Can it be done? Sure anything can be done given sufficient time. But it would be a non-trivial amount of work.  I don't know the exact mechanism since I've not implemented that myself, but you'd need to end threads without ending the connection, maintaining a list of them, and who is waiting for what, and then have a mechanism for pushing data to those threads. I think it would be a lot of work to do.

Implementing the WebSockets (which is basically the same idea) was a fair bit of work and also lead to the need for Host variables (ie data shared between users) - plus of course all the connection management etc. You can't just "stall" a thread waiting, because it's highly unlikely that you can have 1000 threads in an app (just from a RAM perspective.)

Your best bet (and your cheapest), by a long way, is to just upgrade to NT9 and make use of the WebSocket support that is already there.

cheers
Bruce

Alberto

  • Hero Member
  • *****
  • Posts: 1873
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Re: Web notification without sockets
« Reply #4 on: May 19, 2016, 07:10:21 AM »
Ok, may you please take a look at the attached image and tell me if that kind of result is possible with NT9?
Thanks
-----------
Regards
Alberto

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Web notification without sockets
« Reply #5 on: May 22, 2016, 10:37:36 PM »
Of course it's _possible_.
How much work it would be is another question. I imagine a fair bit.

Your graphic shows an environment which is changing _very- quickly. To do that you would want to implement as much as possible of it in JavaScript. For example the graph would best be done with a JavaScript graph widget. (There are lots of them out there, but I haven't done one in JavaScript myself yet.)

WebSockets simply allow you to "push" data to the client. What you do with it there is limited only by your imagination and your skillset.

cheers
Bruce