开发者

Twisted threaded tcp client

I am开发者_Python百科 trying to write a simple TCPServer and a client with Twisted python. Everything is working well; but, there is a way to defer some tasks to different threads? For example, is it possible to do:

  • take an input from the user until \n, then send the data to the server;
  • accept all the incoming messages from the server and write to the screen;

simultaneously?

Which are best practices?

Thank you for your help.

—Donovan


Threads are one implementation strategy for doing these things simultaneously. Twisted generally goes with another strategy - non-blocking I/O and an event multiplexer (eg select(2)).

If you want to handle input from stdin while you have a TCPServer running, all that means is that you want to use Twisted's APIs for reading from stdin, just like you're using Twisted's APIs for handling network connections.

See twisted.internet.stdio.StandardIO for that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜