Skip to content

Commit

Permalink
updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
kerryjiang committed Jul 20, 2024
1 parent c236816 commit d130e42
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,56 @@
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 += (s, p) =>
{
Console.WriteLine(p.ToString());
}

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();

```

0 comments on commit d130e42

Please sign in to comment.