python 中的网络应用程序和 GUI
我正在编写一个通过网络发送文件的应用程序,我想开发一个自定义协议,以便在功能丰富性方面不限制自己(http 不合适,最近的可能是 bittorrent 协议)。
我尝试过使用twisted,我已经构建了一个很好的应用程序,但是twisted 中存在一个错误,导致我的GUI 阻塞,所以我必须切换到另一个框架/策略。
你有什么建议?使用原始套接字和使用gtk mainloop(工具包中有类似select的功能)太难了吗?
在不同线程中运行两个主循环是否可行?
寻求建议
I'm writing an application that sends files over network, I want to develop a custom protocol to not limit myself in term on feature richness (http wouldn't be appropriate, the nearest thing is the bittorrent protocol maybe).
I've tried with twisted, I've built a good app but there's a bug in twisted that makes my GUI blocking, so I've to switch to another framework/strategy.
What do you suggest? Using raw sockets and using gtk mainloop (there are select-like functions in the toolkit) is too much difficult?
It's viable running two mainloops in different threads?
Asking for suggestions
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
免责声明:我对网络应用程序缺乏经验。
话虽这么说,原始套接字并不是很难理解/使用,特别是如果您不太担心优化的话。当然,这需要更多思考。但使用 GTK 和原始套接字应该相当简单。特别是因为您已经使用了扭曲框架(IIRC),它只是抽象了套接字管理的一些更具体的细节。
Disclaimer: I have little experience with network applications.
That being said, the raw sockets isn't terribly difficult to wrap your head around/use, especially if you're not too worried about optimization. That takes more thought, of course. But using GTK and raw sockets should be fairly straightforward. Especially since you've used the twisted framework, which IIRC, just abstracts some of the more nitty-gritty details of socket managing.
两个线程:一个用于 GUI,一个用于发送/接收数据。 Tkinter 将是一个完美的工具包。您不需要扭曲或任何其他外部库或工具包 - 开箱即用的内容足以完成工作。
Two threads: one for the GUI, one for sending/receiving data. Tkinter would be a perfectly fine toolkit for this. You don't need twisted or any other external libraries or toolkits -- what comes out of the box is sufficient to get the job done.
如果您的应用程序有点类似于 bittorrent,为什么不检查 Deluge 的源代码 http://deluge-torrent.org/ 并从中构建?它是用Python编写的,它确实使用bittorrent协议并且它确实有一个GTK用户界面。
If your application is somewhat similar to bittorrent, why not check the source code of Deluge http://deluge-torrent.org/ and build from it? It is written in Python, it does use the bittorrent protocol and it does have a GTK user interface.
作为扭曲和您似乎正在使用的任何 GUI 库的替代方案,尝试 PyQt< /a>?它在同一事件循环中提供 GUI 和非阻塞套接字。这样您就不必担心互操作性问题,这似乎是您面临的问题。
希望这有帮助!
As an alternative to twisted and whatever GUI library you seem to be using, how about trying PyQt? It provides a GUI and non-blocking sockets all in the same event loop. That way you don't have to worry about interoperability issues, which seem to be the issue you are facing.
Hope this helps!