在Twisted中实现Direct Connect客户端的正确方法? [英] Proper way to implement a Direct Connect client in Twisted?

查看:139
本文介绍了在Twisted中实现Direct Connect客户端的正确方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Direct Connect P2P网络编写Python客户端.本质上,它是通过连接到中央服务器并响应正在搜索文件的其他用户来工作的.

I'm working on writing a Python client for Direct Connect P2P networks. Essentially, it works by connecting to a central server, and responding to other users who are searching for files.

有时,另一个客户端会要求我们连接到他们,他们可能会开始从我们这里下载文件.这是与其他客户端的直接连接,并且不会通过中央服务器.

Occasionally, another client will ask us to connect to them, and they might begin downloading a file from us. This is a direct connection to the other client, and doesn't go through the central server.

处理与其他客户端的这些连接的最佳方法是什么?我目前正在使用一个Twisted反应器连接到服务器,但最好是有多个反应器,每个客户端一个,每个反应器在不同的线程中运行?还是最好有一个完全独立的Python脚本来执行与客户端的连接?

What is the best way to handle these connections to other clients? I'm currently using one Twisted reactor to connect to the server, but is it better have multiple reactors, one per client, with each one running in a different thread? Or would it be better to have a completely separate Python script that performs the connection to the client?

如果还有其他我不知道的解决方案,我很想听听.我是Twisted编程的新手,因此欢迎您提出建议和其他资源.

If there's some other solution that I don't know about, I'd love to hear it. I'm new to programming with Twisted, so I'm open to suggestions and other resources.

谢谢!

推荐答案

在不了解协议所有细节的情况下,我仍然建议使用单个反应堆-反应堆可以很好地缩放 (尤其是先进的功能,例如PollReactor),这样您就可以避免与线程相关的开销(毕竟,Twisted和其他异步系统是通过避免这种开销来提高基本性能的方式).实际上,Twisted中的线程主要在您需要连接其功能可能会阻塞您的库的情况下有用.

Without knowing all the details of the protocol, I would still recommend using a single reactor -- a reactor scales quite well (especially advanced ones such as PollReactor) and this way you will avoid the overhead connected with threads (that's how Twisted and other async systems get their fundamental performance boost, after all -- by avoiding such overhead). In practice, threads in Twisted are useful mainly when you need to interface to a library whose functions could block on you.

这篇关于在Twisted中实现Direct Connect客户端的正确方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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