Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kerryjiang/websocket4net
A popular .NET WebSocket Client
https://github.com/kerryjiang/websocket4net
client csharp websocket
Last synced: 3 days ago
JSON representation
A popular .NET WebSocket Client
- Host: GitHub
- URL: https://github.com/kerryjiang/websocket4net
- Owner: kerryjiang
- License: apache-2.0
- Created: 2012-08-03T06:27:51.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2024-11-09T17:42:18.000Z (about 1 month ago)
- Last Synced: 2024-12-12T23:08:40.928Z (10 days ago)
- Topics: client, csharp, websocket
- Language: C#
- Homepage:
- Size: 15.5 MB
- Stars: 775
- Watchers: 80
- Forks: 274
- Open Issues: 92
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WebSocket4Net
[![build](https://github.com/kerryjiang/WebSocket4Net/workflows/build/badge.svg)](https://travis-ci.org/kerryjiang/WebSocket4Net)
[![MyGet Version](https://img.shields.io/myget/websocket4net/vpre/WebSocket4Net)](https://www.myget.org/feed/websocket4net/package/nuget/WebSocket4Net)
[![NuGet Beta Version](https://img.shields.io/nuget/vpre/WebSocket4Net.svg?style=flat)](https://www.nuget.org/packages/WebSocket4Net/)
[![NuGet Version](https://img.shields.io/nuget/v/WebSocket4Net.svg?style=flat)](https://www.nuget.org/packages/WebSocket4Net/)
[![NuGet](https://img.shields.io/nuget/dt/WebSocket4Net.svg)](https://www.nuget.org/packages/WebSocket4Net)
[![Badge](https://img.shields.io/badge/link-996.icu-red.svg)](https://996.icu/#/en_US)A popular .NET WebSocket Client
This new version is built on SuperSocket 2.0 and modern .NET (.NET Core). It includes breaking changes from the previous WebSocket4Net version, so code adjustments may be necessary for upgrading.
## Usage 1: Read messages from event handler.
```csharp
using WebSocket4Net;
var websocket = new WebSocket("https://localhost/live");
websocket.PackageHandler += (sender, package) =>
{
Console.WriteLine(package.Message);
}await websocket.OpenAsync();
websocket.StartReceive();
await websocket.SendAsync("Hello");
//...
await websocket.CloseAsync();
```
## Usage 1: Read messages on demand.
```csharp
using WebSocket4Net;
var websocket = new WebSocket("https://localhost/live");
await websocket.OpenAsync();
await websocket.SendAsync("Hello");
while (true)
{
var package = await websocket.ReceiveAsync();if (package == null)
break;Console.WriteLine(package.Message);
}//...
await websocket.CloseAsync();
```