简体   繁体   English

如何编写 tcp 服务器使用 Future 或 .net 异步或其他?

[英]How to write a tcp server use Future or .net async or others?

yes,there is so many sample for a tcp server,but I can't find one use scala future or c#/f# async/awite是的,tcp 服务器的样本太多了,但我找不到一个使用 scala 未来或 c#/f# async/awite

Is future/async suitable for writing a simple tcp server,like echo server?未来/异步是否适合编写简单的 tcp 服务器,如 echo 服务器?

or if there is a server/client modle like smtp,the server and client will talk many times in a session(helo/ok from/ok rcpt/ok data/ok quit/ok),is future or async suitable for this modle?is there some possible that the serve A first get HELO from client A but then talk to client B with other smtp command like "mail from"?或者如果有像 smtp 这样的服务器/客户端模型,服务器和客户端将在会话中多次交谈(helo/ok from/ok rcpt/ok data/ok quit/ok),未来或异步适合这个模型吗?是否有可能服务 A 首先从客户端 A 获得 HELO,然后使用其他 smtp 命令(例如“来自”)与客户端 B 交谈?

where to find the sample code that a echo server use Future or async/awit/Task?在哪里可以找到回显服务器使用 Future 或 async/awit/Task 的示例代码?

Thanks!谢谢!

TCP servers are pretty complex beasts, and since the data is a stream (not a series of bounded packets), it isn't usually directly amenable to just an "await some data" API. TCP 服务器是相当复杂的野兽,由于数据是 stream(不是一系列有界数据包),因此通常不能直接接受“等待一些数据” ZDB974238714CA8DE634A7CE1D0F The raw sockets API has an async component, but it isn't the shape you would normally expect.原始 sockets API 有一个异步组件,但它不是您通常期望的形状。

Kestrel can be used to construct an async TCP server using the "pipelines" API, which deals with all the things like back-buffer management (for when you can't yet consume an incomplete frame) - I have a blog series here on that , however: no official client-side API exists (yet) for "pipelines"; Kestrel 可用于使用“管道”API 构建异步 TCP服务器,它处理诸如后台缓冲区管理之类的所有事情(当您还不能使用不完整的帧时) - 我有一个关于此的博客系列,但是:“管道”不存在(尚未)官方客户端 API; again, the same blog series discusses how you can use Pipelines.Sockets.Unofficial to bridge that gap.同样,同一个博客系列讨论了如何使用Pipelines.Sockets.Unofficial来弥补这一差距。

However!然而! I wonder if what you really want here is a message passing library that sits on top of the TCP layer, so you can just say "send a message" and "await a reply message".我想知道你在这里真正想要的是一个位于 TCP 层之上的消息传递库,所以你可以说“发送消息”和“等待回复消息”。 Many such libraries exist, but they invariably change the shape of the underlying data protocol, as they will be introducing "framing" etc. This means that they may not be suitable choices if you intend to implement a pre-existing protocol (as the choices won't align).存在许多这样的库,但它们总是会改变底层数据协议的形式,因为它们将引入“框架”等。这意味着如果您打算实现预先存在的协议(作为选择),它们可能不是合适的选择不会对齐)。

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

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