SignalR self-hosted, SignalR boarding

Source: Internet
Author: User

SignalR self-hosted, SignalR boarding

Source code

https://github.com/xlb378917466/Chat.Server

1. Use the console program to host the SignalR server. This requires the use of Owin middleware,

2. Implement a server-side ChatHub

 public class ChatHub : Hub    {        public void Send(string name, string message)        {            Clients.All.addMessage(name, message);        }        public override Task OnConnected()        {            Console.WriteLine("Client connected: " + Context.ConnectionId);            return base.OnConnected();        }        public override Task OnDisconnected(bool stopCalled)        {            Console.WriteLine("Client disconnected: " + Context.ConnectionId);            return base.OnDisconnected(stopCalled);        }    }

3. Build a Chat. WebClient that can communicate through the web page. In this example, you can solve the problem of reconnection.

This placeEasily encountered problemsYes,

A connection error occurs because the SignalR of the server is inconsistent with the client version,

The other is the big and lowercase case in js. For example, the HUB on the server is ChatHub, but only $. connection. chatHub can be used in js. Otherwise, an error is returned.

 

4. To build a CS communication Client, you need to use Microsoft. AspNet. SignalR. Client

Build a proxy through Microsoft. AspNet. SignalR. Client and send messages through the proxy

 

Signalr MSDN Technical Documentation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.