c# websocket code example

Example 1: websocketsharp

using System;
using WebSocketSharp;

namespace Example
{
  public class Program
  {
    public static void Main (string[] args)
    {
      using (var ws = new WebSocket ("ws://dragonsnest.far/Laputa")) {
        ws.OnMessage += (sender, e) =>
            Console.WriteLine ("Laputa says: " + e.Data);

        ws.Connect ();
        ws.Send ("BALUS");
        Console.ReadKey (true);
      }
    }
  }
}

Example 2: websocketsharp

var ws = new WebSocket ("ws://example.com");

Example 3: F# websocket

using System;
using System.Threading;

class Counter
{
  static void Main()
  {
    for (int i = 1; i <= 10; i++)
    {
      Console.WriteLine(i);
      Thread.Sleep(500);
    }
  }
}

Tags:

Misc Example