python 中的网络应用程序和 GUI

发布于 2024-09-04 14:20:01 字数 273 浏览 8 评论 0原文

我正在编写一个通过网络发送文件的应用程序,我想开发一个自定义协议,以便在功能丰富性方面不限制自己(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

山田美奈子 2024-09-11 14:20:01

免责声明:我对网络应用程序缺乏经验。

话虽这么说,原始套接字并不是很难理解/使用,特别是如果您不太担心优化的话。当然,这需要更多思考。但使用 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.

风筝在阴天搁浅。 2024-09-11 14:20:01

两个线程:一个用于 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.

挽你眉间 2024-09-11 14:20:01

如果您的应用程序有点类似于 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.

水中月 2024-09-11 14:20:01

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文