Design Question for Python Networking

I am currently writing a Python project with a client and part of a server. I have problems with a network message, so I need to explain some things ...

The client basically performs the operations that the server tells him and sends the results of the operations back to the server. I need a way for bidirectional communication over a TCP socket.

Current situation

I am currently using LineReceiverTwisted structures on the server side and simple Python socket(and ssl) on the client side (because I was unable to implement Twisted correctly PushProducer). On the client side there is Queue, which is filled with data that should be sent to the server; the subprocess continuously outputs data from the queue and sends it to the server (see code below).

This scenario works well, if only the client pushes his results to the manager. It is not possible for the server to send data to the client. More precisely, the client cannot receive data sent by the server.

Problem

I need a way to send commands from the server to the client.

I was thinking of listening for incoming data in a client loop, which I use to send data from the queue:

def run(self):
    while True:
        data = self.queue.get()
        logger.debug("Sending: %s", repr(data))
        data = cPickle.dumps(data)
        self.socket.write(data + "\r\n")
        # Here would be a good place to listen on the socket

But there are several problems with this solution:

  • SSLSocket.read()
  • , .

, Queue.get_nowait() Queue.get(), , .

Twisted? Twisted, . , LineReceiver , - , . lineReceived.

Twisted ( , ), ? . , ; - , .

+3
2

" ".

. "" "". .

Twisted ( , ), ?

. .

, ;

, .

, . "" "".


" , - . - ?"

.

, .

"", - - "", .

. - - , . ( API select):

  • , "-".

  • ( ).

, -.

, , . , .

0

" , LineReceiver , - , . lineReceived ".

protocol.transport.write , lineReceived.

+2

Source: https://habr.com/ru/post/1766067/


All Articles