This article is a mirror article of machine translation, please click here to jump to the original article.

View: 36969|Reply: 3

[ASP.NET] SignalR for websocket communication (3)

[Copy link]
Posted on 7/7/2017 2:26:50 PM | | | |
First of all, the main purpose of using websockets is to let the backend actively push data to the frontend to process the display

1: SignalR connects to the server for the first time



When we open the page, we want the websocket connection to be successful, and then push the existing data to us first, what should we do?

First, we inherit the Hub class and then rewrite the OnConnected method with the code as follows:


//
        Summary:
        //     Called when the connection connects to this hub instance.
        //
        Return results:
        //     A System.Threading.Tasks.Task
        public virtual Task OnConnected();
After the signalr user connects successfully for the first time, the OnConnected method is triggered, and the Context.ConnectionId is the generated customer ID



Call the Clients.Client method to push data to the specified client Id, and the following all method is defined by ourselves.



2: Actively push data to the front desk

How to actively push data to the front desk through SignalR?

We need to push data to the frontend in the following code:



js method is as follows:



Renderings:






Previous:Blockbuster news! Mini program development is free!
Next:How to disable error prompts when webBrowser displays html content in C# Winform
Posted on 12/29/2017 10:27:27 AM |
I would like to see your SignalR for websocket communication full version 1-3, here I can only see [ASP.NET] SignalR for websocket communication (3)
 Landlord| Posted on 12/29/2017 12:08:28 PM |
522803365 Posted on 2017-12-29 10:27
I would like to see your full version 1-3 of SignalR for websocket communication, here I can only see [ASP.NET] SignalR for websocket communication (3 ...
asp.net mvc4.0 Installing SignalR (1)
http://www.itsvse.com/thread-3837-1-1.html
(Source: Architect)


mvc 4.0 How to use SignalR (2)
http://www.itsvse.com/thread-3838-1-1.html
(Source: Architect)



Posted on 2/8/2022 10:12:42 AM |

I would like to see your SignalR for websocket communication full version 1-3, here I can only see [ASP.NET] SignalR for websocket communication (3)
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com