Usage

Alchemy Websockets is a Visual Studio 2010 project. It can be loaded in the free Visual C# Express and Monodevelop as well (and potentially other compatible IDEs.) It runs in Mono and Windows .NET environments. It officially supports hybi-00, hybi-10, and hybi-17 (rcf6455).

Include Alchemy Websockets as a git submodule in your project, or download and build the solution yourself and include as a dll reference. From there, starting a server is as simple as instantiating an WSServer object, opening the connection, and binding events.

You can also use Alchemy Websockets as a client to connect to other WebSocket servers using the rfc6455 protocol.

Setting up Alchemy Websockets as a Server

//...refs
using Alchemy;
using Alchemy.Classes;

static void Main(string[] args)
{
  var aServer = new WebSocketServer(81, IPAddress.Any) {
    OnReceive = OnReceive,
    OnSend = OnSend,
    OnConnect = OnConnected,
    OnConnected = OnConnect,
    OnDisconnect = OnDisconnect,
    TimeOut = new TimeSpan(0, 5, 0)
  };

  aServer.Start();
}

static void OnConnected(UserContext context)
{
  Console.WriteLine("Client Connection From : " +
  aContext.ClientAddress.ToString());
}

//...etc
      

Setting up Alchemy Websockets as a Client

//...refs
using Alchemy;
using Alchemy.Classes;

static void Main(string[] args)
{
  var aClient = new WebSocketClient("ws://alchemywebsockets.net:81/chat"){
    OnReceive = OnReceive,
    OnSend = OnSend,
    OnConnect = OnConnected,
    OnConnected = OnConnect,
    OnDisconnect = OnDisconnect
  });

  aClient.Connect();
  aClient.Send("Hey!"); // string or byte[]
  aClient.Disconnect();
}

static void OnReceive(UserContext context)
{
  Console.WriteLine("The server said : " + context.DataFrame.ToString());
}

//...etc
      

Example Project

An example application can be seen on alchemy-websockets-example

Client Library

The client library is not necessary; it simply provides a helpful abstraction for older websockets that handles a flash fallback using websocket-js.

You can download the client javascript library at alchemy-websockets-client-library.

License

Licensed under LGPL and MIT. Copyright 2011, Olivine Labs, LLC.