Working with WebSockets for real-time communication scenarios

At the end of the previous section, everything was working fully automated, as expected. However, there is still some room for additional improvements.

As it is, the client-side sends periodical requests to the server-side to see if the email confirmation status has changed. This may lead to a lot of requests to see if there has been a status change or not.

Furthermore, the server-side cannot inform the client-side as soon as an email has been confirmed since it has to wait for a client request to respond to.

In this section, you will learn about the concepts of WebSockets (https://docs.microsoft.com/en-us/aspnet/core/fundamentals/websockets) and how they will allow you to optimize your client-side implementations even more.

WebSockets enable persistent two-way communication channels over TCP, which is especially interesting for applications that need to run real-time communication scenarios (chat, stock tickers, games, and more). It just so happens that our example application is a game, which is one of the main application types that largely benefits from working directly with a socket connection.

Note that you could also consider SignalR as an alternative. SignalR provides a better solution for real-time communication scenarios and encapsulates some of the functionalities that are missing from WebSockets that we may have implemented manually. 

We will cover SignalR in the next chapter, that is, Chapter 6Introducing Razor Components and SignalR

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.243.4