Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #33452 > unrolled thread
| Started by | bit-naughty@hotmail.com |
|---|---|
| First post | 2017-05-31 10:34 -0700 |
| Last post | 2017-06-10 02:13 +0200 |
| Articles | 8 — 4 participants |
Back to article view | Back to comp.lang.javascript
Executing code pushed from the server bit-naughty@hotmail.com - 2017-05-31 10:34 -0700
Re: Executing code pushed from the server "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-05-31 19:43 +0200
Re: Executing code pushed from the server Stefan Weiss <krewecherl@gmail.com> - 2017-05-31 20:25 +0200
Re: Executing code pushed from the server bit-naughty@hotmail.com - 2017-06-01 09:35 -0700
Re: Executing code pushed from the server Stefan Weiss <krewecherl@gmail.com> - 2017-06-09 04:54 +0200
Re: Executing code pushed from the server Richard Maher <maher_rjSPAMLESS@hotmail.com> - 2017-06-01 06:39 +0800
Re: Executing code pushed from the server bit-naughty@hotmail.com - 2017-06-09 08:54 -0700
Re: Executing code pushed from the server Stefan Weiss <krewecherl@gmail.com> - 2017-06-10 02:13 +0200
| From | bit-naughty@hotmail.com |
|---|---|
| Date | 2017-05-31 10:34 -0700 |
| Subject | Executing code pushed from the server |
| Message-ID | <769e8d95-b693-4d1c-ae54-07f273d1c331@googlegroups.com> |
Is there any way some JS code can be SENT TO the client, upon a keypress at the server, and executed there? Like, people are on a website, and when the key is pressed on the server, they see something new happening inside their browser? I'm guessing this is something to do with EventSource and eval, but....*how* though? Thanks.
[toc] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2017-05-31 19:43 +0200 |
| Message-ID | <XnsA786C89DD9ACDeejj99@194.109.6.166> |
| In reply to | #33452 |
bit-naughty@hotmail.com wrote on 31 May 2017 in comp.lang.javascript: > Is there any way some JS code can be SENT TO the client, upon a keypress > at the server, and executed there? Like, people are on a website, and > when the key is pressed on the server, they see something new happening > inside their browser? I'm guessing this is something to do with > EventSource and eval, but....*how* though? A server cannot initiate, it is there to "serve". However, a web-page in a browser can poll the server and get any code and then execute it in the browser. [or even unsafely outside a browser, say in a cscript script.] Whatsapp is an example. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Stefan Weiss <krewecherl@gmail.com> |
|---|---|
| Date | 2017-05-31 20:25 +0200 |
| Message-ID | <ogn1qo$i9i$1@news.albasani.net> |
| In reply to | #33452 |
bit-naughty@hotmail.com wrote: > Is there any way some JS code can be SENT TO the client, upon a keypress > at the server, and executed there? Like, people are on a website, and when > the key is pressed on the server, they see something new happening inside > their browser? > I'm guessing this is something to do with EventSource and eval, > but....*how* though? It's possible, but before we discuss *how*, I'd really like to know *why*. A person manually operating a web server and selectively sending out bits of code is, to put it mildly, an unusual setup. - stefan
[toc] | [prev] | [next] | [standalone]
| From | bit-naughty@hotmail.com |
|---|---|
| Date | 2017-06-01 09:35 -0700 |
| Message-ID | <ed64dd4c-30c1-46bc-9158-2e30c6334d75@googlegroups.com> |
| In reply to | #33454 |
On Wednesday, May 31, 2017 at 11:55:32 PM UTC+5:30, Stefan Weiss wrote: > > Is there any way some JS code can be SENT TO the client, upon a keypress > > at the server, and executed there? Like, people are on a website, and when > > the key is pressed on the server, they see something new happening inside > > their browser? > > I'm guessing this is something to do with EventSource and eval, > > but....*how* though? > > It's possible, but before we discuss *how*, I'd really like to know *why*. > A person manually operating a web server and selectively sending out bits of > code is, to put it mildly, an unusual setup. Hehe it IS! :) I'm thinking of kind of.... the Unix console, you know, when you shutdown it tells EVERYBODY'S terminals - "Shutting down now" or whatever - I kinda wanted to do that, web wise :) That's text of course, but you get the idea....
[toc] | [prev] | [next] | [standalone]
| From | Stefan Weiss <krewecherl@gmail.com> |
|---|---|
| Date | 2017-06-09 04:54 +0200 |
| Message-ID | <ohd2lm$o1i$1@news.albasani.net> |
| In reply to | #33482 |
bit-naughty@hotmail.com wrote:
> On Wednesday, May 31, 2017 at 11:55:32 PM UTC+5:30, Stefan Weiss wrote:
>
>>> Is there any way some JS code can be SENT TO the client, upon a keypress
>>> at the server, and executed there? Like, people are on a website, and when
>>> the key is pressed on the server, they see something new happening inside
>>> their browser?
>>> I'm guessing this is something to do with EventSource and eval,
>>> but....*how* though?
>>
>> It's possible, but before we discuss *how*, I'd really like to know *why*.
>> A person manually operating a web server and selectively sending out bits of
>> code is, to put it mildly, an unusual setup.
>
> Hehe it IS! :) I'm thinking of kind of.... the Unix console, you know,
> when you shutdown it tells EVERYBODY'S terminals - "Shutting down now" or
> whatever - I kinda wanted to do that, web wise :) That's text of course, but
> you get the idea....
I get the idea. I think I'm still missing the point of it, how it could be
useful in practice, but lets put that aside now.
It's been a very long time since I saw an unexpected wall(1) message in a
terminal, and I have my doubts if this is really something we want to port
from Unix to web applications. When it happened, chances were good you were
busy editing a file and then it just WROTE OVER whatever you had on your
display. Not fun.
Server outage/maintainence announcements for web applications are typically
not done in the way you describe - "hey everybody, server's going down NOW!"
- but rather well in advance. Hours/days/weeks, depending on the
application. Not only does this give the users enough time to finish their
tasks, it also removes the requirement of immediate communication (press a
key on the server). You can just add the notification in whatever component
builds the HTML, and it will be displayed the next time the user loads a page.
Simplified pseudo code:
<.... html ....>
<? if file "admin-announcement.html" exists ?>
<? include file "admin-announcement.html" ?>
<? end if ?>
<.... html ....>
That could be all there is to it. Depending on your interface, you may
already have a way to notify users of events that require their attention.
For example, the time tracking software I use will have a maintainance
outage next Saturday, so they made the bell icon in the sidebar noticably
active earlier this week, and they added an animated "new messages" counter,
similar to what you see on social media when you're notified about a new
message.
http://i.imgur.com/OmGCX9g.png
(this is after I read the announcement)
There are special situations where users may not load new pages for a long
time and a different approach is needed. Examples for this would be online
games where users stay on the same page for hours, or single-page web
applications that only communicate with the server via XHR. But in all those
scenarios you already have a communication channel with the users; all you
need to do is add support for the display of admin announcements on the client.
If you really really want to communicate with your users directly, at the
press of a key, and you do not already have an active communication channel,
your best options are polling (as Evertjan suggested) or WebSockets (as
Richard Maher suggested). Both use up resources on the client and the
server, which is why I would strongly recommend against doing this unless
you have a better reason than "I kinda wanted to do that".
Both options are also much more complex than (I think) you imagine them. You
need something on the server to register your key press. What that is
depends very much on your setup. Is it a server (instance) you rented
somewhere? Are you actually sitting in the server room with a keyboard
attached to the box? Does the server have a graphical UI running? Which OS
is it running?
Maybe the simplest solution would be to use an existing chat client. Every
time the user loads a page, they (re-)join the chat in the background. An
administrator can also join the chat (using any old browser, and not
necessarily on the server) and send messages. The admin messages are then
displayed on every user's screen.
I'm not saying you should do it that way. It's a waste of resources for
little benefit, but it can do what you asked, and it's relatively easy to
implement.
- stefan
[toc] | [prev] | [next] | [standalone]
| From | Richard Maher <maher_rjSPAMLESS@hotmail.com> |
|---|---|
| Date | 2017-06-01 06:39 +0800 |
| Message-ID | <ogngni$7dn$1@gioia.aioe.org> |
| In reply to | #33452 |
On 01-Jun-17 1:34 AM, bit-naughty@hotmail.com wrote: > Is there any way some JS code can be SENT TO the client, upon a keypress at the server, and executed there? Like, people are on a website, and when the key is pressed on the server, they see something new happening inside their browser? > I'm guessing this is something to do with EventSource and eval, but....*how* though? > > > Thanks. > WebSockets may be able to help you. I like the Push API and with Firebase's implementation there is topic-based subscription. Why can't the code you want to execute be on the page?
[toc] | [prev] | [next] | [standalone]
| From | bit-naughty@hotmail.com |
|---|---|
| Date | 2017-06-09 08:54 -0700 |
| Message-ID | <edd491da-7fdf-4dfc-8578-f28494d2428e@googlegroups.com> |
| In reply to | #33452 |
Uhh no Stefan, it *has* to be Push. (Out of curiosity, how would I architect this with WebSockets?) But no.... - it HAS to be Push.
[toc] | [prev] | [next] | [standalone]
| From | Stefan Weiss <krewecherl@gmail.com> |
|---|---|
| Date | 2017-06-10 02:13 +0200 |
| Message-ID | <ohfdj3$61t$1@news.albasani.net> |
| In reply to | #33515 |
bit-naughty@hotmail.com wrote: > Uhh no Stefan, it *has* to be Push. (Out of curiosity, how would I > architect this with WebSockets?) But no.... - it HAS to be Push. I still don't understand why, but whatever. WebSockets can be used to implement server push. If you want to build this yourself, there are plenty of examples for the client side on the web. I can't say anything about the server side, because you haven't answered my questions. I stand by my suggestion to use an existing chat implementation as simplest solution for you (ideally containing both the server and client components). MDN even has a page dedicated to writing WebSocket client applications. The example they use is - surprise surprise - a web chat. Next time, please reply to the message you're referring to, and quote some context. - stefan
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web