<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Yunus Emre KAŞ</title>
    <description>The latest articles on DEV Community by Yunus Emre KAŞ (@emrekas).</description>
    <link>https://dev.to/emrekas</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F289204%2Fb792b54c-5afa-4fb4-abba-f107a8ce6c4e.png</url>
      <title>DEV Community: Yunus Emre KAŞ</title>
      <link>https://dev.to/emrekas</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/emrekas"/>
    <language>en</language>
    <item>
      <title>What is SignalR Core? How does it work?</title>
      <dc:creator>Yunus Emre KAŞ</dc:creator>
      <pubDate>Wed, 19 Aug 2020 18:24:41 +0000</pubDate>
      <link>https://dev.to/emrekas/what-is-signalr-core-how-does-it-work-49f5</link>
      <guid>https://dev.to/emrekas/what-is-signalr-core-how-does-it-work-49f5</guid>
      <description>&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;The subheadings of our topic will be as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  What is SignalR Core?&lt;/li&gt;
&lt;li&gt;  Where do we use it?&lt;/li&gt;
&lt;li&gt;  How does it work ?&lt;/li&gt;
&lt;li&gt;  Data Transfer Types&lt;/li&gt;
&lt;li&gt;  Hubs&lt;/li&gt;
&lt;li&gt;  Benefits&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is SignalR Core?
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h3&gt;
  
  
  Where Do We Use It?
&lt;/h3&gt;

&lt;p&gt;We can use the fast and simultaneous transfer of data wherever we want.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Games&lt;/li&gt;
&lt;li&gt;  Social Media (comments, messaging, notification)&lt;/li&gt;
&lt;li&gt;  Auction&lt;/li&gt;
&lt;li&gt;  Voting&lt;/li&gt;
&lt;li&gt;  Financial transactions&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How Does SignalR Core Work?
&lt;/h2&gt;

&lt;p&gt;Let’s open a little bit about the phrase “It allows us to run a client-side javascript code from the server side”. In a normal scenario, the client throws an HTTP Request to the server, the server processes the request and returns a Response to the client. But SignalR is not like that either. It happens but not exactly. 😂 So how is it happening?&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;So let’s say that our server or browser does not support Websocket, then what will happen? Can’t I use SignalR?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;SignalR: Wait, it’s not over, nephew. You should first see transport methods.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  SignalR Core Data Transport Methods
&lt;/h2&gt;

&lt;p&gt;There are 3 different transfer types in SignalR Core, among which are the WebSocket, Server-Sent Events and Long Polling methods.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6nwgehkjm0e52rsfiu00.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6nwgehkjm0e52rsfiu00.jpeg" alt="SignalR Core Transports"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is WebSocket? How does it work?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flunrhmoxx5imwfbqkmpq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flunrhmoxx5imwfbqkmpq.png" alt="websocket"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;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,  &lt;strong&gt;Handshake (Handshake / Agreement)&lt;/strong&gt;  and  &lt;strong&gt;Data Transfer&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;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  &lt;strong&gt;handshake&lt;/strong&gt;  request sent by the client:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;View of a handshake response sent by the presenter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTP/1.1 101 Switching Protocols  
Upgrade: websocket  
Connection: Upgrade  
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=  
Sec-WebSocket-Protocol: chat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Websocket connections are made over  &lt;strong&gt;ws&lt;/strong&gt;  (WebSocket) and  &lt;strong&gt;wss&lt;/strong&gt;  (WebSocket Secure / SSL) URI schemes.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Requirements for Websocket connection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;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.  &lt;a href="https://caniuse.com/#feat=websockets" rel="noopener noreferrer"&gt;For detailed information.&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  How Does Server-Sent Events Work ?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fps4iapqh11g4mk3doihg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fps4iapqh11g4mk3doihg.png" alt="server-sent-event"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this type, the client sends a request to the server, and the server returns a response containing Content-Type: text / event-stream. The connection is formed in this way. Event-stream starts listening to the server. An events consisting of a server are broadcast over the Event-stream. You can pull data with the EventSource object via Javascript.  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format" rel="noopener noreferrer"&gt;For more detailed information.&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  How Does Long Polling Work?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fetg4naq6kxw104opds5q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fetg4naq6kxw104opds5q.png" alt="Long Polling"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“What did this server do to you bro?” is a method you can tell.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Hubs
&lt;/h2&gt;

&lt;p&gt;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  &lt;a href="https://msgpack.org/" rel="noopener noreferrer"&gt;MessagePack&lt;/a&gt;. MessagePack usually creates smaller messages compared to JSON.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Browsers must support XHR level 2 to provide MessagePack protocol support.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Advantages
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  Automatically chooses the data transfer type&lt;/li&gt;
&lt;li&gt;  It is easy to understand and write because it is on .Net&lt;/li&gt;
&lt;li&gt;  Since it is open source, it is always open to development&lt;/li&gt;
&lt;li&gt;  It doesn’t use JQuery like the old SignalR, so it’s straight forward&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks you for reading. You can reach me on  &lt;a href="https://www.linkedin.com/in/emrekas/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt;  for your comments and suggestions.&lt;/p&gt;

</description>
      <category>signalr</category>
      <category>realtime</category>
      <category>aspnetcore</category>
      <category>dotnet</category>
    </item>
  </channel>
</rss>
