简体   繁体   中英

TCP Sockets - sending and receiving at different ports

I try to write a python script (3.5.2) that uses nonblocking tcp sockets. The sockets receive data from an application, does some conversion stuff and sends it back to that application. Because the conversion could take some time it should be async. Furthermore my application is not able to send and receive data at the same port. So my idea is to send the data from my application via port 4711 (just an example) to my python script and send the results back via port 4712.

Up to now I did not work with python or sockets at all. My question is about architecture. I want to ensure that my script can receive data all the time via 4711 (several different tasks), is working on that data (if there is something to do) and sends the data back via 4712 - everything async. So my application is able to send a big work load (several tasks) and as soon as the result(s) are ready send it back, one by one.

I am a bit overhelmed at the moment about sockets and I dont know how to ensure that the receiving and sending does not block itself or the conversion process etc. Can someone provide a description or an example how this has to look like?

My question is about architecture.

1. asyncio

Use asyncio concurrent network communications. Run event loop with uvloop .

2. Any MQ solution

RabbitMQ, ZeroMQ, etc, any of them will allow you to place new tasks in the queue and run as many workers to make computations as you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM