[UWP]如何编写能够异步读写的高性能UWP套接字客户端? [英] [UWP]How to write high-performance, UWP socket clients capable of asynchronous reading and writing?

查看:72
本文介绍了[UWP]如何编写能够异步读写的高性能UWP套接字客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在将我的脚趾浸入UWP开发(来自Unix背景),我发现自己很困惑。我想开发一个tcp客户端,它可以使用
C#中的Windows.Networking.Sockets API以异步,解耦的方式发送和接收数据。我遇到的所有示例都实现了同步的,协议级的双向通信:发送内容,然后期待响应。


然而,发送和接收完全解耦是很常见的。例如:一个专用的接收器线程,轮询/在套接字上休眠,直到某些数据进入,其他线程在需要时发送数据。


这很容易做到,例如,Boost的asio C ++中的库使用async_read_some()之类的函数来填充缓冲区,然后在遇到足够的数据包时解码其中的消息。


但是在UWP中,看起来即使是线程API也不鼓励专用线程。轻量级"任务"调度到操作系统管理的线程池似乎是模型(我知道存在长时间运行任务的概念)。


利用Windows.Networking的正确方法是什么.Sockets实现灵活,高性能的tcp客户端(或服务器),优雅地支持完全解耦的读/写?有没有很好的资源涵盖这些例子?


谢谢,


Bart

解决方案


我问团队这个问题。可能会有一些时间延迟。


感谢您的耐心等待。


致以诚挚的问候,


Roy


Hi,

I'm dipping my toes into UWP development (coming from a Unix background) and am finding myself puzzled. I'd like to develop a tcp client that can both send and receive data in an asynchronous, decoupled fashion using the Windows.Networking.Sockets API in C#. All the examples I've come across implement synchronous, protocol-level bi-directional communication: send something, then expect a response.

However, it's common to have sending and receiving fully decoupled. For example: a dedicated receiver thread that polls/sleeps on a socket until some data comes in and other threads that send data when needed.

This is pretty easy to do with e.g., Boost's asio library in C++ using functions like async_read_some() to fill up buffers and then decode messages within them when enough packets have come across.

But in UWP, it looks like even the threading API discourages dedicated threads. Lightweight "tasks" dispatched to an OS-managed thread pool seem to be the model (I'm aware that the notion of long-running tasks exists).

What is the right way to leverage Windows.Networking.Sockets to implement a flexible, high-performance tcp client (or server) that elegantly supports fully decoupled reading/writing? Are there any good resources that cover such examples?

Thank you,

Bart

解决方案

Hi,

I'm asking the team about this. There might be some time delay.

Thank you for your patience.

Best regards,

Roy


这篇关于[UWP]如何编写能够异步读写的高性能UWP套接字客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆