How can client know the changing from server side? - node.js

In Node. How I can push a notify to the clients with new information that another client made changing to server, even client is offline and online back.
Ex: I logged on my account to 3 device, 1 on my laptop, 1 on my PC, 1 on my mobile. On my laptop, I change the account’s information but I leaved the browser on my PC. When server send a notify to all clients, the online devices can receive the new information, without offline device. I want when I back access to my PC, I can detect the change from server without HTTP request.

You are looking for websockets.
https://developer.mozilla.org/en-US/docs/Web/API/WebSocket

Related

GraphQL subscription does not receive messages after successful handshake

I have created a simple GraphQL Subscription using Nest.js/Apollo GraphQL over Node.js. My client application which is a react.js/apollo client works find with the server. The client subscibes to the server via GraphQL similar to:
subscription
{
studentAdded
{
id
}
}
My problem is that it works only locally. When I deploy my server back-end to a hosted docker over internet, client won't receive data anymore.
I have traced the client, it sends GET request on ws://api.example.com:8010/graphql and receives the successful HTTP/1.1 101 Switching Protocols response. However, nothing is received from server like when the server was on my local machine. Checking the remote server log showed me that the client successfully connects to server. There, I can see onConnect log messages.
Now I need any guidance to solve the problem.
I check several things myself. Firstly, I thought WebSocket address is prohibited in the network but then realized that it is on same port as normal HTTP. Secondly, supposed that WebSocket messages/frames are transmitted over UDP but I was not correct, it is over TCP and no need to worry about network settings.
Additionally I have read several github threads and StackOverflow questions. But did not find any clue. I am not directly using Node.js/WebSocket, instead, I am using Nest.js/GraphqQL subscription. It has made my search tougher.
Your help is highly appreciated.

Web Push - Do they use public servers like google etc?

As I understand Web Push, the messages are transferred over a public server like googleapi, mozilla or whatever. Is this correct?
So I can't use this functionality in a private network with a private server without access to the public network? (How can this function be used in a private environment?)
Yes, Web Push uses a public server to deliver push notifications. This is done to use just one connection to receive push notifications from multiple websites.
From Firefox documentation:
What information does Firefox use to provide Web Push?
Firefox maintains an active connection to a push service in order to receive push messages as long as it is open. The connection ends when Firefox is closed. On our server we store a randomized identifier for your browser, along with a randomized identifier for each site you authorize.
On Firefox for desktop, the push service is operated by Mozilla. Firefox for Android uses a combination of the Mozilla Web Push service and Google’s Cloud Messaging platform to deliver notifications to Firefox for Android.
In both cases, push messages are encrypted per the IETF spec and only your copy of Firefox can decipher them. The encrypted messages are stored on the server until they are delivered or expire.
Similarly, Chrome receives push notification via Google servers. If these servers are inaccessible, Web Push won't work.
One possible way to use Web Push in an isolated network is to set up your own push server. The code of Mozilla push server is available online, so with some luck you may be able to make it work in your network. Then you'll have to configure all Firefox instances to use your server (the preference is named dom.push.serverURL). I don't know if anything similar is possible with Chrome.
You may also use Notifications API to show notifications without using Web Push. This only works while the user has your website open, however.
Simple Answer: You can use it in private networks. Google/Mozilla/... is only involved, if the Website author designed it to like so. It's not required.

How does a server verify a client in a mulitplayer game?

So tons of games are run via custom clients (call it game.exe) but must communicate to a server. How does the developer ensure that only connections from the custom client are accepted and not any other requests, say from a web browser?
Ex: I play game.exe and my requests go thought no problem. I then submit a request to that game server using my web browser or some other POST utility, but it is ignored by the game server to prevent cheating.
Is this done via secret strings that are coded into game.exe and sent with every request? It seems to vulnerable to intercept them with a packet sniffer. Same applies with a client-side SSL certificate, someone could easily find the key file in the game files and forge requests.
Typically games that are stand alone applications - with a .exe extension on Windows, for example - do not use http as their protocols, unlike web browsers.
Irrespective of the protocol used, however, games typically send credentials - often account credentials, similar to a user name and password - when the connection is established. Many games uses a persistent TCP connection, so this only had to be done when logging in to the game.

ssmtp: queuing emails when smtp server is unreachable

I have ssmtp installed and configured on my linux box. It connects to a remote smtp server provided by my hosting provider and works faultlessly.
My linux box is connected to an APC UPS, and emails are sent from the ups deamon (apcupsd) when the machine looses comms with the UPS, or the battery in the UPS becomes faulty.
apcupsd also sends out "onbattery" or "onmains" emails. The problem is however that the linux box is the only thing on the UPS, things like my router and hub are NOT on the UPS, and so switch off in the event of a power outage.
Is there anyway to have the emails queued up when the linux box is unable to connect to the smtp server, and then deliver them when everything comes online?
if I try "mailq" during a power outage, it states that the queue is empty, even tho I know that an email was generated and failed to be delivered.
Thanks in advance,
Phil.

Whitelisted chromecast works with default tictactoe app ID but not mine

I am trying to get the tic tac toe demo from github working on my Chromecast after changing only the app id of the clients. With the default app id, I have been able to launch and play the game with an android client and a mac client.
I have:
Added my Chromecast device on the developer console (it has a green status indicator)
Set (via the Android Chromecast app) the Chromecast to send the device serial number
Verified that the serial number is correct
Verified with both the Android and Windows Chromecast apps that the serial# setting is retained
Power cycled the Chromecast
Setup an app id in the developer console (status is a grey circle labeled 'Unpublished')
Entered an internet accessible (not local) URL for the app id
Installed the receiver app at the above url and verified I can access it from a browser on the same network as the Chromecast
Also tried a local IP address (192.168.x.x) which I understand is supported as well
Modified the web client ttt.js file to use my app id (and verified app id is correct)
Modified the android client (GameActivity.java) to use my app id (and verified app id)
Did a git diff to make sure that I didn't inadvertently change anything else
Verified that my local copy of the source is the latest from git
When running the android client I can connect to my Chromecast but the Chromecast home screen shows "Brain Freeze", "We're sorry, but something could not load", "Activity aborted".
The logcat console in eclipse for the android device reports, "ConnectionResultCallback. Unable to launch the game. statusCode: 2002".
The web client on the Mac results in the same messages on the Chromecast and
'"reason":"CANCELLED","type":"LAUNCH_ERROR"'
on the web page output.
Is there a way to get more information from the Chromecast to indicate what is going wrong with the launch?
Follow Up
It turns out that the issue was in my network setup and not in my chromecast setup. After sniffing the network traffic with wireshark, I could see that the ARP request to retrieve the MAC address of my server was not getting a response. I am running my server on Virtualbox with a bridged adapter but needed to turn on promiscuous mode (allow all). Now the chromecast successfully launches the receiver app and I can play the tic tac toe game when using an HTTP based URL. (I need to fix the certificate for HTTPS).
Thanks Les, for the effort.
Did you verify that [x] send my serial # to Google has been checked (using the setup app)?
Also, did you wait 15 minutes and then restart your device (power cycle)?

Resources