Real Time in Javascript

Asked

Viewed 106 times

0

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

On the website globoesporte.with, specifically on the real-time broadcast pages of the games, when opening the Console, I realized that the content of the page (the starting bids) was updated even without any kind of request (at least visible in the console) of type XHR or Fetch.

How is that possible?

  • Websockets is one of the possibilities

  • To complement Rodrigo’s answer: For Javascript, you can use https://socket.io

1 answer

0

This is possible Gracas Sockets TCP.

A connection http normal creates a single communication route with the server. In other words, the client has to be making requests to the server to receive its answers. In the case of an environment Realtime, this would be too heavy, IE the client would be all the time asking questions to the server, to check if there is update.

When you create a connection Socket TCP, we have two ways of communication, that is, besides the client knowing the server, the server knows the client, and can send messages to the client.

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

When you log on to the site to follow the Altime game, the browser makes a request to the server to establish a socket connection, thus creating a hub, thanks to this, your browser does not need to keep making requests every second to check if there is an update to show you, but the server that will send a message to your browser.

I don’t know which server language you use, but I use C#, which has as a great socket solution, Signalr, Here is a microsoft tutorial on Signalr.

I know Java also has a socket solution, but I don’t know its name.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.