简体   繁体   English

.NET的Node.js

[英]Node.js for .NET

I know about projects like Edge.js which allow for C# and Node.js connectivity, but I'm talking about something different. 我知道像Edge.js这样允许C#和Node.js连接的项目,但我说的是不同的东西。 Is there a library for C#, that allows you to build scalable, non-blocking I/O, single threaded, async event servers in C#, similar to the servers you can build with Node.js? 是否有一个C#库,它允许您在C#中构建可伸缩的,非阻塞的I / O,单线程,异步事件服务器,类似于您可以使用Node.js构建的服务器? A library that also has the unique event model of Node.js, single threaded for user code, multi threaded for file/network events and native code (correct me if I'm wrong). 一个库,它还具有Node.js的唯一事件模型,用于用户代码的单线程,用于文件/网络事件和本机代码的多线程(如果我错了,请纠正我)。 Of course I know about ASP and WCF, and OSS projects like this , but I'm looking for something that gives you performance comparable to Node.js, a kind of Node.js port to C#. 当然我知道ASP和WCF,以及像这样的 OSS项目,但我正在寻找能够提供与Node.js相当的性能的东西,Node.js是一种到C#的Node.js端口。 Do you know of any such library, and what would it take to build it? 你知道任何这样的图书馆,它需要什么来建立它?

Single threaded or multi threaded? 单螺纹还是多螺纹?

If you want a single threaded managed process that does all its work using APC and completion ports, you are going to have to hand code it. 如果您希望使用单线程托管进程使用APC和完成端口完成所有工作,则必须手动编写代码。 Building it would be risky and tricky. 建立它将是冒险和棘手的。 -- Sam Salton - 萨姆索尔顿

Obivously, being single threaded makes code easier to write since you don't need to work with locks and mutexes. 显而易见,单线程使代码更容易编写,因为您不需要使用锁和互斥锁。 There's just one thread reading/modifying program state data which keeps things simple. 只有一个线程读取/修改程序状态数据,这使得事情变得简单。 All calculations occur on seperate threads and return to the main thread when the results are ready. 所有计算都在单独的线程上进行,并在结果准备好后返回主线程。 All file/network events branch out and return to the main thread after the op is complete. 操作完成后,所有文件/网络事件都会跳出并返回主线程。

Related but different questions: 相关但不同的问题:

  1. Non-blocking single threaded web server 非阻塞单线程Web服务器
  2. Minimal web server 最小的Web服务器
  3. Single threaded async events 单线程异步事件

Probably useful projects: 可能有用的项目:

  1. ALE comes the closest to what I want, syntax similar to Node.js ALE最接近我想要的,语法类似于Node.js
  2. Manos de mono , a single threaded server for C# Manos de mono ,C#的单线程服务器
  3. A message loop in C# , that processes events on a single thread C#中的消息循环 ,用于处理单个线程上的事件
  4. Wrappers for Libuv in C# ( 1 , 2 ) 在C#包装器Libuv( 12
  5. Anna for HTTP requests only (no binary), syntax similar to Node.js Anna仅用于HTTP请求(无二进制),语法类似于Node.js

I already posted this to your first related question, which may answer your question as well: 我已将此问题发布到您的第一个相关问题,这也可以回答您的问题:

Here is an open-source example written in VB.NET and C#: 这是一个用VB.NET和C#编写的开源示例:

https://github.com/perrybutler/dotnetsockets/ https://github.com/perrybutler/dotnetsockets/

It uses Event-based Asynchronous Pattern (EAP), IAsyncResult Pattern and thread pool (IOCP). 它使用基于事件的异步模式(EAP),IAsyncResult模式和线程池(IOCP)。 It will serialize/marshal the messages (messages can be any native object such as a class instance) into binary packets, transfer the packets over TCP, and then deserialize/unmarshal the packets at the receiving end so you get your native object to work with. 它会将消息(消息可以是任何本机对象,如类实例)序列化/编组为二进制数据包,通过TCP传输数据包,然后在接收端反序列化/解组数据包,这样您就可以使用本机对象来处理。 This part is somewhat like Protobuf or RPC. 这部分有点像Protobuf或RPC。

It was originally developed as a "netcode" for real-time multiplayer gaming, but it can serve many purposes. 它最初是作为实时多人游戏的“网络代码”开发的,但它可以用于多种用途。 Unfortunately I never got around to using it. 不幸的是我从来没有使用它。 Maybe someone else will. 也许其他人会。

The source code has a lot of comments so it should be easy to follow. 源代码有很多注释,因此应该很容易理解。 Enjoy! 请享用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM