ByronAP.Net.WebSockets 0.8.1.1

dotnet add package ByronAP.Net.WebSockets --version 0.8.1.1
NuGet\Install-Package ByronAP.Net.WebSockets -Version 0.8.1.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ByronAP.Net.WebSockets" Version="0.8.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ByronAP.Net.WebSockets --version 0.8.1.1
#r "nuget: ByronAP.Net.WebSockets, 0.8.1.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ByronAP.Net.WebSockets as a Cake Addin
#addin nuget:?package=ByronAP.Net.WebSockets&version=0.8.1.1

// Install ByronAP.Net.WebSockets as a Cake Tool
#tool nuget:?package=ByronAP.Net.WebSockets&version=0.8.1.1

ByronAP.Net.WebSockets

ByronAP.Net.WebSockets is a .NET library that simplifies the usage of client websockets.

Sponsor NuGet version (SoftCircuits.Silk) FOSSA Status

Usage

using System;
using System.Threading.Tasks;

namespace WebSocketUsageDemo
{
    class Program
    {
        const string WebSocketHost = "wss://echo.websocket.org";
        const string TestMessage = "Hi, this is a websocket text message.";

        static async Task Main()
        {
            // Create an instance of the WebSocketOptions class
            var options = new ByronAP.Net.WebSockets.WebSocketOptions(WebSocketHost);
            // setup options as needed

            // create a client instance and make sure it is automatically disposed of by a using statement
            using var client = new ByronAP.Net.WebSockets.WebSocketClient(options);

            // hookup to the events we want to receive
            client.ConnectionStateChanged += Client_ConnectionStateChanged;
            client.MessageReceived += Client_MessageReceived;
            client.DataReceived += Client_DataReceived;

            // start the connection and ensure it connected sucessfully
            var connResult = await client.ConnectAsync();
            if(!connResult.Item1)
            {
                // connection failed
                Console.WriteLine($"{DateTime.Now} ERROR: {connResult.Item2}");
                await Task.Delay(2000);
                return;
            }

            // send our test message
            Console.WriteLine($"{DateTime.Now} Message Sent: {TestMessage}");
            await client.SendTextAsync(TestMessage);

            // wait a bit before exiting the app
            await Task.Delay(2000);
        }

        /// <summary>
        /// This gets called when the state of the connection changes
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="newWebSocketState"></param>
        /// <param name="oldWebSocketState"></param>
        private static void Client_ConnectionStateChanged(object sender, System.Net.WebSockets.WebSocketState newWebSocketState, System.Net.WebSockets.WebSocketState oldWebSocketState)
        {
            Console.WriteLine($"{DateTime.Now} State Changed: from {oldWebSocketState} to {newWebSocketState}");
        }

        /// <summary>
        /// This gets called when a text message is received
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="message"></param>
        private static void Client_MessageReceived(object sender, string message)
        {
            Console.WriteLine($"{DateTime.Now} Message Received: {message}");
        }

        /// <summary>
        /// This gets called when binary data is received
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="data"></param>
        private static void Client_DataReceived(object sender, byte[] data)
        {
            Console.WriteLine($"{DateTime.Now} Data Received: {data.Length} bytes");
        }
    }
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on ByronAP.Net.WebSockets:

Package Downloads
CoinCapApi

CoinCap API Client Library

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.8.1.1 965 5/16/2023
0.8.0.1 1,355 12/15/2022
0.7.7 932 8/23/2021
0.7.6 956 7/6/2021
0.7.5 877 7/6/2021