In honor of Fleck, a C# websocket library, becoming Mono compatible, I’m finally giving it some exposure.
Fleck was written in response to a lack of lightweight websockets support in C#. It was forked from the Nugget project, and stripped down to the core. The result is an API similar to em-websockets that stays out of your way.
If you’re in a browser that supports WebSockets (Chrome, Safari, Firefox trunk), go ahead and type a bit. Your keystrokes will be captured, and broadcasted to any other users on the page. If this page is lonely, you can open a second browser window to test it out.
Get rolling with Fleck by creating a new WebSocketServer
with the address to
bind. Call Start()
to start the server and configure callbacks for OnOpen
,
OnClose
, and OnMessage
.
In the example, connected sockets are added to an array and broadcasted to when
OnMessage
is triggered.
The client side script listens for keypresses and sends them to the websocket. On receiving a message, which is just a single letter in this case, the corresponding letter will be lit up.
With it all put together, WebSockets makes for a simple way to connect users together through the browser without plugins, polling, or other ugly frameworks.
28 May 2011