Realtime in JavaScript

0

I'm a beginner (not so much) in the programming area, and I came across the following situation:

At globoesporte.com , specifically on the real-time broadcast pages of the games, when you open the Console I noticed that the content of the page (the game's bids) was updated even without any kind of request (at least visible on the console) of type XHR or Fetch . >

How is this possible?

    
asked by anonymous 14.04.2018 / 22:50

1 answer

0

This is possible thanks to TCP Sockets .

A normal link connection creates a single path of communication with the server. In other words, the client has to be making requests to the server to receive their answers. In the case of a realtime environment, this would be very cumbersome, ie the client would spend all the time asking the server for updates.

When you create a TCP Socket, you have two communication paths, ie the client knows the server, the server knows the client, and can send messages to the client.

/ p>

What you noticed on the site of globoesporte.com, is exactly a connection created by a socket, basically what happens is as follows.

When you enter the site to follow the realtime game, the browser asks the server to establish a socket connection, thus creating a hub , so your browser does not need to stay making requests every second to check if there is any update to show you, but the server that will send a message to your browser.

I do not know which language server you use, but I use C #, which has a great socket solution, the SignalR, Here is a microsoft tutorial on SignalR .

I know Java also has a socket solution, but I do not know its name.

    
15.04.2018 / 01:45