• Stars
    star
    2,221
  • Rank 19,889 (Top 0.5 %)
  • Language
    C#
  • License
    MIT License
  • Created over 13 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

C# Websocket Implementation

Fleck

Build status NuGet

Fleck is a WebSocket server implementation in C#. Branched from the Nugget project, Fleck requires no inheritance, container, or additional references.

Fleck has no dependency on HttpListener or HTTP.sys meaning that it will work on Windows 7 and Server 2008 hosts. WebSocket Remarks - Microsoft Docs

Example

The following is an example that will echo to a client.

var server = new WebSocketServer("ws://0.0.0.0:8181");
server.Start(socket =>
{
  socket.OnOpen = () => Console.WriteLine("Open!");
  socket.OnClose = () => Console.WriteLine("Close!");
  socket.OnMessage = message => socket.Send(message);
});
        

Supported WebSocket Versions

Fleck supports several WebSocket versions of modern web browsers

  • Hixie-Draft-76/Hybi-00 (Safari 5, Chrome < 14, Firefox 4 (when enabled))
  • Hybi-07 (Firefox 6)
  • Hybi-10 (Chrome 14-16, Firefox 7)
  • Hybi-13 (Chrome 17+, Firefox 11+, Safari 6+, Edge 13+(?))

Secure WebSockets (wss://)

Enabling secure connections requires two things: using the scheme wss instead of ws, and pointing Fleck to an x509 certificate containing a public and private key

var server = new WebSocketServer("wss://0.0.0.0:8431");
server.Certificate = new X509Certificate2("MyCert.pfx");
server.Start(socket =>
{
  //...use as normal
});

Having issues making a certificate? See this guide to creating an x509 by @AdrianBathurst

SubProtocol Negotiation

To enable negotiation of subprotocols, specify the supported protocols on the WebSocketServer.SupportedSubProtocols property. The negotiated subprotocol will be available on the socket's ConnectionInfo.NegotiatedSubProtocol.

If no supported subprotocols are found on the client request (the Sec-WebSocket-Protocol header), the connection will be closed.

var server = new WebSocketServer("ws://0.0.0.0:8181");
server.SupportedSubProtocols = new []{ "superchat", "chat" };
server.Start(socket =>
{
  //socket.ConnectionInfo.NegotiatedSubProtocol is populated
});

Custom Logging

Fleck can log into Log4Net or any other third party logging system. Just override the FleckLog.LogAction property with the desired behavior.

ILog logger = LogManager.GetLogger(typeof(FleckLog));

FleckLog.LogAction = (level, message, ex) => {
  switch(level) {
    case LogLevel.Debug:
      logger.Debug(message, ex);
      break;
    case LogLevel.Error:
      logger.Error(message, ex);
      break;
    case LogLevel.Warn:
      logger.Warn(message, ex);
      break;
    default:
      logger.Info(message, ex);
      break;
  }
};

Disable Nagle's Algorithm

Set NoDelay to true on the WebSocketConnection.ListenerSocket

var server = new WebSocketServer("ws://0.0.0.0:8181");
server.ListenerSocket.NoDelay = true;
server.Start(socket =>
{
  //Child connections will not use Nagle's Algorithm
});

Auto Restart After Listen Error

Set RestartAfterListenError to true on the WebSocketConnection

var server = new WebSocketServer("ws://0.0.0.0:8181");
server.RestartAfterListenError = true;
server.Start(socket =>
{
  //...use as normal
});

More Repositories

1

webpack-livereload-plugin

LiveReload during webpack --watch
JavaScript
203
star
2

dokku-supervisord

Use supervisord as the runner within dokku
Shell
121
star
3

dokku-shoreman

Run all process types with dokku
Shell
98
star
4

que-web

A web interface for the Que queue
Ruby
88
star
5

mark-loader

Wrap Webpack modules with performance.mark and performance.measure
JavaScript
61
star
6

PostLog

An HttpAppender for log4net
C#
21
star
7

vim-jade

Vim syntax highlighting for the Jade templating engine.
Vim Script
21
star
8

hubot-newrelic2

New Relic stats from Hubot
CoffeeScript
13
star
9

sql-setup

Setting up a Postgresql instance
10
star
10

hampool

NCVEC amateur radio question pools in JSON format
JavaScript
9
star
11

que-testing

Make assertions on enqueued jobs
Ruby
9
star
12

angularjs-testing-library

Simple and complete AngularJS DOM testing utilities that encourage good testing practices.
TypeScript
7
star
13

pmrpc

JSON-RPC over postMessage
TypeScript
6
star
14

chumps

JavaScript
5
star
15

rn-mini

React Native + Snack primer
3
star
16

ng-templatecache

Convert html to Angular $templateCache entries
JavaScript
3
star
17

lua_kata

Lua
3
star
18

ServerSent

JavaScript
3
star
19

love_life

Game of life in Lua Love
Lua
3
star
20

KnockoutList

Todos.js in Knockout
JavaScript
3
star
21

Fleck.WinFormsExample

Example of using Fleck with Winforms
C#
3
star
22

SimpleMVVM

Example application displaying MVVM. Also, implements an AttachedBehavior
2
star
23

ActionContainer

A container agnostic dynamic service agent implementation
C#
2
star
24

dotfiles

My dotfiles
Vim Script
2
star
25

rsturing

Turing machine in rust
Rust
1
star
26

WindsorMefMvc

A combination of Castle Windsor and MEF with ASP MVC
JavaScript
1
star
27

hubot-lunch-rotation

Rotate lunch weekly by individuals
CoffeeScript
1
star
28

lua_euler

Working through Project Euler with Lua for some practice
Lua
1
star
29

lcthw

Learn C the Hard Way Exercises
C
1
star
30

minsin

Sinatra+Minitest Skeleton
Ruby
1
star
31

js-hs

Me just playing with Haskell
Haskell
1
star
32

bayesball

A Bayes Classification Implementation
Ruby
1
star
33

RubyTutorial

Following along RubyTutorial.org
Ruby
1
star
34

cors-test

Testing redirects of cors
1
star
35

kr

Going through K&R
C
1
star
36

chinook-web

JavaScript
1
star
37

SilverlightMultiUpload

A silverlight control allowing multiple files to be uploaded asynchronously.
1
star
38

tree

Ruby
1
star
39

bigo

Rust
1
star
40

append-basename-webpack-plugin

Append to basenames before resolution in webpack
JavaScript
1
star
41

statianzo.github.com

Trying out Jekyll
CSS
1
star
42

KnockoutListTested

A tested version of KnockoutList
JavaScript
1
star
43

JQueryList

Don't try this at home
JavaScript
1
star
44

andy

Views for Android using YAML
Ruby
1
star
45

yellowbrick

Send email -> Post blog
Ruby
1
star
46

MvcToFubu

Testing out MVC3 and Fubu
JavaScript
1
star
47

scoutcoding

Sample projects for scouting merit badge
Ruby
1
star
48

fubu-template-example

For demonstration purposes
C#
1
star
49

MultiThreadFileAccessWebApp

A web app that uses a background thread to create files from database request
JavaScript
1
star