CSDN

ZslLoveMiwa的博客

Fleck

                                                                                                                                                                Fleck是一个在C#中的WebSocket服务器端的一个实现.。分支自Nugget项目, Fleck不需要任何的继承、容器亦或是需要增加的引用就可以使用。

实例

下面是一个把客户端网页发来的消息回发到客户端的服务器程序。

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);
});

支持WebSocket的网页版本

Fleck支持多种现代的具有WebSocket功能版本的浏览器。

  • 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+)

支持使用安全的网络通讯协议 (wss://)

启用安全的网络连接需要如下两件事:

1. 使用“wss”代替原来的“ws”;

2. 将Fleck指定一个包含一个共钥和私钥的x509证书;

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

子协议协商系统

为了启用子协议协商,在 WebSocketServer.SupportedSubProtocols属性上进行指定声明。 协商的子协议将在套接字的 ConnectionInfo.NegotiatedSubProtocol上可用。如果在客户端请求(在用于WebSocket打开阶段握手的头字段①)上没有找到支持的子协议,则连接将被关闭。

①这个地方我也不是很懂,要是有大神懂欢迎指正!

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

自定义日志系统

Fleck可以讲日志注入Log4Net等的一些第三方的日志系统中。仅仅需要用目标的日志行为方法注入一下FleckLog.LogAction 属性即可使用。

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;}
};

禁用Nagle的缓冲器算法

将WebSocketConnection.ListenerSocket 中的 NoDelay设置为true。
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
});

监听过程中出现错误自动重启

设置WebSocketConnection 的 RestartAfterListenError 属性为true。

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

Fleck原文

 

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

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+)

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
});

SubProtocol Negotiation

To enable negotiation of subprotocols, specify the supported protocols on theWebSocketServer.SupportedSubProtocolsproperty. 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
});

原文地址

Fleck说明文档翻译相关推荐

  1. 【iOS官方文档翻译】iOS蓝牙的基本概念

    之前写了[iOS官方文档翻译]iOS的蓝牙连接.数据接收及发送一文,介绍了怎样进行蓝牙通讯,但是很多基本概念没有进行解释,看起来可能有点吃力,所以现在再翻译一篇苹果对官方蓝牙4.0一些基本概念介绍的文 ...

  2. Sencha-概念-Layouts(布局)(官网文档翻译8)

    Sencha-概念-Layouts(布局)(官网文档翻译8) 介绍和HBox 布局描述了在您的应用程序的组件的大小和位置.例如,一个电子邮件客户端可能具有固定到左边的消息的列表,以说,可用的宽度的三分 ...

  3. Laravel 5.6 中文文档翻译完成,译者 60 人,耗时 10 天

    图片来自 laravel-news.com Laravel 5.6 的文档地址: Laravel 5.6 文档页面 总结 Laravel 5.6 文档翻译完成,总共耗时 10 天,参与用户 60 人. ...

  4. python翻译程序-Python桌面应用案例:TXT文档翻译工具(源代码)

    搞定了Word文档和PDF文档翻译工具的案例,总觉得还差了一点,仔细想了下,明白了,原来差了一个TXT文本文件翻译工具案例.这个就更简单了--在PDF文档翻译工具基础上加了两个函数,就可以支持TXT文 ...

  5. TiDB 官方设计文档翻译(三)

    这个系列共三篇译文:  TiDB 官方设计文档翻译(一)  TiDB 官方设计文档翻译(二)  TiDB 官方设计文档翻译(三) 原文:  https://pingcap.github.io/blog ...

  6. TiDB 官方设计文档翻译(二)

    这个系列共三篇译文:  TiDB 官方设计文档翻译(一)  TiDB 官方设计文档翻译(二)  TiDB 官方设计文档翻译(三) 原文:  https://pingcap.github.io/blog ...

  7. TiDB 官方设计文档翻译(一)

    TiDB是新兴的NEWSQL数据库,由国内的PINGCAP团队研发.  有关于TiDB的架构.部署和运维,官方有中文的文档,链接是:  https://github.com/pingcap/docs- ...

  8. 欢迎参与 KubeVela 官方文档翻译活动

    来源 | 阿里巴巴云原生公众号 背景 KubeVela v1.0 启用了新的官网架构和文档维护方式,新增功能包括文档版本化控制.i18n 国际化以及自动化流程.但目前 KubeVela 官方文档只有英 ...

  9. Sencha-概念-Events(事件)(官网文档翻译10)

    Sencha-概念-Events(事件)(官网文档翻译10) 煎茶Touch 2的组件和类的触发广泛的事件,在其生命周期的不同点.活动让你的代码,它周围的变化作出反应,并在煎茶触摸是一个关键的概念. ...

最新文章

  1. Java transient
  2. tensorflow中sess.run第一个参数衣服不能随便穿
  3. 第七天学习Java的笔记(IDEA环境配置)
  4. Spring_Bean的作用域---和使用外部属性文件
  5. 探索HTTP传输中gzip压缩的秘密
  6. 玩转FusionCharts:Y轴数字形式(如去掉K)
  7. 基于JAVA+SpringMVC+Mybatis+MYSQL的体育竞赛比赛赛事管理系统
  8. java 对象流 乱码,JAVA 中的 IO 流
  9. php基于新浪ip库获取城市,WordPress-利用新浪IP库获取评论用户所在城市信息!
  10. 【转】余弦相似度及基于python的三种代码实现、与欧氏距离的区别
  11. GNS3使用二:通过ASDM管理ASA防火墙
  12. teamtalk简介
  13. NW和Electron的区别
  14. window.btoa与window.atob
  15. 电容介绍|电容的种类和作用
  16. 陈都灵现身海南国际电影节,新片《关索岭》票房有望超《阿凡达》
  17. InvalidDefinitionException: No serializer found for class... 因为没有给对象写get、set方法
  18. 【机器人原理与实践(二)】单目摄像头标定与单目测距
  19. 大师的话一语道破.强烈建议阅读
  20. 2020年Web前端面试题及答案----ES6篇

热门文章

  1. CSS实现反方向圆角
  2. python +appium实现原理_Appium+python自动化(四十)-Appium自动化测试框架综合实践 - 代码实现(超详解)...
  3. catic备份mysql,Catic构建与部署
  4. 产品读书《极简生活法则》
  5. 弘辽科技:淘宝类目属性的型号是什么?
  6. 解决richedit的内容不能超过64k的方法
  7. java中封装类Feild和使用setter和getter方法访问封装的类Feild
  8. 一个实验了解什么是ISIS
  9. 四面楚歌,商汤科技该如何在AI领域破局
  10. 小霸王其乐无穷~FC红白机游戏600合集(支持mac 12.x系统)