Hello everyone, What is SignalR Core in the third part of the series How to communicate with React with SignalR Core using JWT? How does it work ? I will try to explain their subjects.
The subheadings of our topic will be as follows:
- What is SignalR Core?
- Where do we use it?
- How does it work ?
- Data Transfer Types
SignalR is an open source library with which you can create real time applications. It contains APIs that allow us to run a client-side code from the server side.
We can use the fast and simultaneous transfer of data wherever we want.
- Social Media (comments, messaging, notification)
- Financial transactions
The client sends an HTTP Request to the server, SignalR processes this request and by default determines the ideal transfer type. If the server and client support Websocket, Websocket protocol is selected as the transfer method. Because the best SignalR transfer method is the Websocket method.
So let’s say that our server or browser does not support Websocket, then what will happen? Can’t I use SignalR?
SignalR: Wait, it’s not over, nephew. You should first see transport methods.
There are 3 different transfer types in SignalR Core, among which are the WebSocket, Server-Sent Events and Long Polling methods.
By default, SignalR Core proceeds by trying the above methods in order to find the best transfer protocol, and when it finds the best method, it establishes the connection through this transfer method. Most modern browsers support Websocket, which is the best method for SignalR.
It is a protocol that you can transfer bi-directional data over TCP between client and server. Like JWT, it is an RFC6455 standard. It is examined in two parts as Websocket, Handshake (Handshake / Agreement) and Data Transfer.
As can be understood from above, our first request is sent as an HTTP Request. This first request and the process of raising the connection is called handshake. View of a handshake request sent by the client:
GET /chat HTTP/1.1 Host: server.example.com Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== Origin: http://example.com Sec-WebSocket-Protocol: chat, superchat Sec-WebSocket-Version: 13
View of a handshake response sent by the presenter:
HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo= Sec-WebSocket-Protocol: chat
Websocket connections are made over ws (WebSocket) and wss (WebSocket Secure / SSL) URI schemes.
If the conditions are suitable, the connection is upgraded and turns into a ws connection. Thus, a two-way asynchronous transfer path over TCP is formed between the server and the client.
Requirements for Websocket connection
WebSocket requires the server to use Windows Server 2012 or Windows 8 and .NET Framework 4.5. Latest versions of modern browsers generally accept Websocket connections. For detailed information.
This method is an example of coyote. When the client makes a request, the server receives the request and holds it until there is a change. As soon as there is any change in the data requested, it returns to the client. The client makes a request again.
“What did this server do to you bro?” is a method you can tell.
SignalR communicates between the client and the server through hubs. Hub, on the other hand, is a high-level pipeline that enables server and client to use each other’s methods. You can use parameter and model binding properties in these methods. SignalR provides two built-in hub protocols: a text protocol based on JSON and a binary protocol based on MessagePack. MessagePack usually creates smaller messages compared to JSON.
Browsers must support XHR level 2 to provide MessagePack protocol support.
- Automatically chooses the data transfer type
- It is easy to understand and write because it is on .Net
- Since it is open source, it is always open to development
- It doesn’t use JQuery like the old SignalR, so it’s straight forward
Thanks you for reading. You can reach me on Linkedin for your comments and suggestions.