All Projects → sacOO7 → Socketclusterclientdotnet

sacOO7 / Socketclusterclientdotnet

Licence: apache-2.0
C# client for socketcluster framework in node.js

Projects that are alternatives of or similar to Socketclusterclientdotnet

Httwrap
General purpose, simple but useful HttpClient wrapper for .NET & Xamarin/Mono
Stars: ✭ 39 (-35%)
Mutual labels:  xamarin, mono
32feet
Personal Area Networking for .NET
Stars: ✭ 395 (+558.33%)
Mutual labels:  windows-phone, xamarin
Tensorflowsharp
TensorFlow API for .NET languages
Stars: ✭ 3,027 (+4945%)
Mutual labels:  xamarin, mono
ably-dotnet
.NET, Xamarin and Mono client library SDK for Ably realtime messaging service
Stars: ✭ 32 (-46.67%)
Mutual labels:  xamarin, mono
Embeddinator 4000
Tools to turn .NET libraries into native libraries that can be consumed on Android, iOS, Mac, Linux and other platforms.
Stars: ✭ 735 (+1125%)
Mutual labels:  xamarin, mono
PCLExt.FileStorage
Portable Storage APIs
Stars: ✭ 35 (-41.67%)
Mutual labels:  xamarin, mono
Mvvmcross
The .NET MVVM framework for cross-platform solutions, including Xamarin.iOS, Xamarin.Android, Windows and Mac.
Stars: ✭ 3,594 (+5890%)
Mutual labels:  xamarin, mono
Caliburn.micro
A small, yet powerful framework, designed for building applications across all XAML platforms. Its strong support for MV* patterns will enable you to build your solution quickly, without the need to sacrifice code quality or testability.
Stars: ✭ 2,404 (+3906.67%)
Mutual labels:  windows-phone, xamarin
Mathparser.org Mxparser
Math Parser Java Android C# .NET/MONO (.NET Framework, .NET Core, .NET Standard, .NET PCL, Xamarin.Android, Xamarin.iOS) CLS Library - a super easy, rich and flexible mathematical expression parser (expression evaluator, expression provided as plain text / strings) for JAVA and C#. Main features: rich built-in library of operators, constants, math functions, user defined: arguments, functions, recursive functions and general recursion (direct / indirect). Additionally parser provides grammar and internal syntax checking.
Stars: ✭ 624 (+940%)
Mutual labels:  xamarin, mono
Firesharp
An asynchronous cross-platform .Net library for Firebase
Stars: ✭ 601 (+901.67%)
Mutual labels:  xamarin, mono
Portable-WebDAV-Library
Moved to codeberg.org - https://codeberg.org/DecaTec/Portable-WebDAV-Library - The Portable WebDAV Library is a strongly typed, async WebDAV client library which is fully compliant to RFC 4918, RFC 4331 and "Additional WebDAV Collection Properties". It is implemented as .NETStandard 1.1 library in oder to be used on any platform supporting .NETS…
Stars: ✭ 45 (-25%)
Mutual labels:  xamarin, mono
Csla
A home for your business logic in any .NET application.
Stars: ✭ 865 (+1341.67%)
Mutual labels:  xamarin, mono
uno.toolkit.ui
A set of custom controls for the WinUI and the Uno Platform not offered out of the box by WinUI, such as Card, TabBar, NavigationBar, etc.
Stars: ✭ 45 (-25%)
Mutual labels:  xamarin, mono
AppRopio.Mobile
AppRopio - mobile apps builder for iOS/Android based on Xamarin
Stars: ✭ 16 (-73.33%)
Mutual labels:  xamarin, mono
Sharpcaster
Chromecast C# SDK for Windows, Windows Phone, .NET 4.5.1, Xamarin.iOS and Xamarin.Android platforms.
Stars: ✭ 245 (+308.33%)
Mutual labels:  windows-phone, xamarin
Gray hat csharp code
This repository contains full code examples from the book Gray Hat C#
Stars: ✭ 301 (+401.67%)
Mutual labels:  xamarin, mono
Standard.licensing
Easy-to-use licensing library for .NET Framework, Mono, .NET Core, and Xamarin products
Stars: ✭ 239 (+298.33%)
Mutual labels:  xamarin, mono
Mobile Sdk
CARTO Mobile SDK core project
Stars: ✭ 116 (+93.33%)
Mutual labels:  windows-phone, xamarin
Uno
Build Mobile, Desktop and WebAssembly apps with C# and XAML. Today. Open source and professionally supported.
Stars: ✭ 6,029 (+9948.33%)
Mutual labels:  xamarin, mono
Moonsharp
An interpreter for the Lua language, written entirely in C# for the .NET, Mono, Xamarin and Unity3D platforms, including handy remote debugger facilities.
Stars: ✭ 926 (+1443.33%)
Mutual labels:  xamarin, mono

.Net Socketcluster Client

Overview

This client provides following functionality

  • Support for emitting and listening to remote events
  • Automatic reconnection
  • Pub/sub
  • Authentication (JWT)

Client supports following platforms

  • .Net 2.0
  • .Net 3.5
  • .Net 4.0
  • .Net standard 1.3 onwards
  • .Net Core 1.0 onwards
  • Xamarin.Android
  • Xamarin.iOS
  • Unity

License

Apache License, Version 2.0

Usage via Nuget

    Install-Package ScClient.Official

Nuget Gallery link : https://www.nuget.org/packages/ScClient.Official/

Usage using source files

Library is built on top of Websocket4Net and Newtonsoft.Json. Install those packages via nuget and add source files into project

Description

Create instance of Socket class by passing url of socketcluster-server end-point

    //Create a socket instance
    string url = "ws://localhost:8000/socketcluster/";
    var socket = new Socket(url);

Important Note : Default url to socketcluster end-point is always ws://somedomainname.com/socketcluster/.

Registering basic listeners

Create a class implementing BasicListener interface and pass it's instance to socket setListener method


        internal class MyListener : IBasicListener
        {
            public void OnConnected(Socket socket)
            {
                Console.WriteLine("connected got called");
            }

            public void OnDisconnected(Socket socket)
            {
                Console.WriteLine("disconnected got called");
            }

            public void OnConnectError(Socket socket, ErrorEventArgs e)
            {
                Console.WriteLine("on connect error got called");
            }

            public void OnAuthentication(Socket socket, bool status)
            {
                Console.WriteLine(status ? "Socket is authenticated" : "Socket is not authenticated");
            }

            public void OnSetAuthToken(string token, Socket socket)
            {
                socket.setAuthToken(token);
                Console.WriteLine("on set auth token got called");
            }

        }

        internal class Program
        {
            public static void Main(string[] args)
            {
                var socket = new Socket("ws://localhost:8000/socketcluster/");
                socket.SetListerner(new MyListener());
            }
        }


Connecting to server

  • For connecting to server:
    //This will send websocket handshake request to socketcluster-server
    socket.Connect();
  • By default reconnection to server is not enabled , to enable it :
    //This will set automatic-reconnection to server with delay of 3 seconds and repeating it for 30 times
    socket.SetReconnectStrategy(new ReconnectStrategy().SetMaxAttempts(30));
    socket.Connect()
  • To disable reconnection :
   socket.SetReconnectStrategy(null);

Emitting and listening to events

Event emitter

  • eventname is name of event and message can be String, boolean, Long or JSON-object
    socket.Emit(eventname,message);

    //socket.Emit("chat","Hi");
  • To send event with acknowledgement

    socket.Emit("chat", "Hi", (eventName, error, data) =>
    {
       //If error and data is String
       Console.WriteLine("Got message for :"+eventName+" error is :"+error+" data is :"+data);
    });

Event Listener

  • For listening to events :

The object received can be String, Boolean, Long or JSONObject.


    socket.On("chat", (eventName, data) =>
    {
        Console.WriteLine("got message "+ data+ " from event "+eventName);
    });

  • To send acknowledgement back to server

    socket.On("chat", (eventName, data, ack) =>
    {
        Console.WriteLine("got message "+ data+ " from event "+eventName);
        ack(name, "No error", "Hi there buddy");
    });

Implementing Pub-Sub via channels

Creating channel

  • For creating and subscribing to channels:
    var channel=socket.CreateChannel(channelName);
   //var channel=socket.CreateChannel("yolo");


    /**
     * without acknowledgement
     */
     channel.Subscribe();

    /**
     * with acknowledgement
     */

    channel.Subscribe((channelName, error, data) =>
    {
       if (error == null)
       {
             Console.WriteLine("Subscribed to channel "+channelName+" successfully");
       }
    });
  • For getting list of created channels :
    List<Socket.Channel> channels = socket.GetChannels();
  • To get channel by name :
    var channel=socket.GetChannelByName("yell");
    //Returns null if channel of given name is not present

Publishing event on channel

  • For publishing event :
       // message can have any data type
    /**
     * without acknowledgement
     */
     channel.Publish(message);

    /**
     * with acknowledgement
     */
       channel.Publish(message, (channelName, error, data) =>
       {
            if (error == null) {
               Console.WriteLine("Published message to channel "+channelName+" successfully");
            }
       });

Listening to channel

  • For listening to channel event :

    //If instance of channel exists
    channel.OnMessage((channelName, data) =>
    {
         Console.WriteLine("Got message for channel "+channelName+" data is "+data);
    });

    //or
    socket.OnSubscribe(channelName, (channelName, data) =>
    {
        Console.WriteLine("Got message for channel "+channelName+" data is "+data);
    });

Un-subscribing to channel


    /**
     * without acknowledgement
     */

     channel.Unsubscribe();

    /**
     * with acknowledgement
     */

    channel.Unsubscribe((name, error, data) =>
    {
        if (error == null) {
            Console.WriteLine("channel unsubscribed successfully");
        }
    });

Handling SSL connection with server

To enable or disable SSL certficate verification use


socket.SetSSLCertVerification(true/false);

Setting HTTP proxy with server


//args, string : host , int : port
socket.SetProxy(host,port);

Star the repo. if you love the client :).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].