Using Websocket-sharp

Source: Internet
Author: User

Use Websocket-sharp to create a C # version of the WebSocket service

Websocketbehavior is the core object, he contains the OnOpen, OnMessage, OnClose, OnError four methods, and a sessions object. Familiar with WebSocket know the top four methods are used to handle client links, send messages, link close, and errors. Sessions is used to manage some of the connected connections. For each connection, a new Iwebsocketsession object will be added to the id,sessions. The onclose is triggered when the page is closed or refreshed, and the corresponding Iwebsocketsession object is removed in the sessions.

Step 1:using websocketsharp.server;

Step 2: Write the processing class, inheriting the class Websocketserver

Step 3: Create a Websocketserver object

var WSSV = New Websocketserver (4649);

Wssv. Addwebsocketservice<echo> ("/echo");

Wssv. Addwebsocketservice<chat> ("/chat");

Step 4: Start WebSocket server

Wssv. Start ();

Step 5: Stop WebSocket Server

Wssv. Stop (Code,reason);

Using Websocket-sharp

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.