开发者

Twisted threaded tcp client

开发者 https://www.devze.com 2023-01-20 09:28 出处:网络
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

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

精彩评论

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

关注公众号