Chapter 3 - Using Hubs

 Using Hubs

SignalR's main goal is to deliver a real-time experience over HTTP, where both clients and servers can participate in a conversation as senders and listeners at the same time (known as full-duplex communication). A client initiates the flow by starting a new connection, but after that, both types of actors are equally capable of sending and receiving bits of the conversation. In order to deliver such an experience, SignalR comes with two distinct APIs: one called persistent connection, which we can consider to be the low-level API, and one called Hubs, which is built on top of the former and brings a higher-level set of concepts and an easier and straightforward experience for the developer. We'll talk about Hubs first as we want to make our way through the SignalR features, starting from the simplest to use to the more sophisticated.

A Hub can be seen as a set of methods exposed by a server that any client can connect to, in order to perform actions on that server or to retrieve data from it. If you are familiar with the MVC pattern, it looks like a controller because it offers a way to expose the server-side functionalities through methods whose names we are free to define as we prefer. The usual way to exploit this capability is to use names related to our business logic, and SignalR's Hubs are no different; they enable us to do so on top of a bidirectional communication framework.

Example 

How to Use Hub


Step 1 : Open Visual Studio 



Step 2 : search [ asp.net ] template

select [ Asp.NET Web Application (.Net Framwork) ]

click [ Next ] button



Step 3 : set project name[ Example 1 ] 

click [ Create ] button



Step 4 : select [ Empty ]

click [ Create ] button



Step 5 : Right Click On [ Example1] 

 [ Add  ] Click [New Item]


Step 6 : search SignalR click [ SignalR Hub Class (v2) ]

set class Name [ Hubexampl1.cs ] 

Note : If You Not Find [ SignalR Hub Class (v2) ] Templet than Click above Link









                


Comments