real time app with signalr

Post on 28-Jan-2018

118 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Md. Mojammel Haque

persistent connection real-time bi-directional

Consider we have a client side method named MyClientFunc. The server

application will have to call this method. Server will make the call as follows:Clients.Client(id).MyClientFunc()

•Clients:•Clients is a dynamic keyword provided by SignalR.

•Clients contains the list of all connected client of the server.

•Client(id):•Client is also a dynamic keyword provided by SignalR uses to identify the specific client by

is connection Id.

•When a client is connected to the server side application (that is powered by SignalR) are

immediately given a unique id of type Guid. The client can be identified by that id easily.

•MyClientFunc:•The name of the method of Client that will invoke to server

The code go ahead and invoke the method from client to server. The

interaction actually happens over HTTP protocol.

Over HTTP Protocol? What about request-response? How server send

the response without any client request? How server invoke method

from client?

It is possible because SignalR always keeping the persistent connection alive between

client and server. During this connection period there is a dedicated channel is created

between client and server to talk to each other. So if something interesting happen to

the server the server can always push it to client through that channel. Also server can

call the method from client by using that channel.

Consider that we have a function in Server side called MyServerFunc. Now

the client will call it as follows:$.connection.myhub.Server.myServerFunc()

$.connection:

Refers the persistent connection that established by the SignalR between client and

server.

myHub:

This is the name of the Hub class that resides inside server. Client will reach into that

Hub.

A server can have multiple Hubs. So in order to reach into a specific Hub client will

refer the name of that Hub

Server:

Once we reach into the specific hub we can refer the server method by using the

keyword Server.

myServerFunc():

The name of the method that we want to invoke from server to client.

From above discussion we came out a realization that SingalR really abstracts the network transport layer and provides easy APIs on both end.

We don’t have to worry about the network transportation protocols. SingalR automatically figure out the

best transport protocol suited for the communication based on the environments of client and server.

We only maintain the Hub on server side and Hub Proxy on the client side. So we can easily invoke the

method in either end and have easy communication between the client and server.

Contact me at:

mojamcpds@gmail.com

Skype: mojamcpds1

top related