Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Depends. Here are some possibilities:</p> <p>I'm assuming </p> <p>Approach 1. You have a list of commands to send the server, and for some reason can't do them all at once. In that case send a new one as the previous answer returns:</p> <pre><code>class proto(parentProtocol): def stringReceived(self, data): self.handle_server_response(data) next_command = self.command_queue.pop() # do stuff </code></pre> <p>Approach 2. What you send to the server is based on what the server sends you:</p> <pre><code>class proto(parentProtocol): def stringReceived(self, data): if data == "this": self.sendString("that") elif data == "foo": self.sendString("bar") # and so on </code></pre> <p>Approach 3. You don't care what the server sends to, you just want to periodically send some commands:</p> <pre><code>class proto(parentProtocol): def callback(self): next_command = self.command_queue.pop() # do stuff def connectionMade(self): from twisted.internet import task self.task_id = task.LoopingCall(self.callback) self.task_id.start(1.0) </code></pre> <p>Approach 4: Your edit now mentions triggering from another thread. Feel free to check the twisted documentation to find out if <code>proto.sendString</code> is threadsafe. You may be able to call it directly, but I don't know. Approach 3 <em>is</em> threadsafe though. Just fill the queue (which is threadsafe) from another thread.</p> <p>Basically you can store any amount of state in your protocol; it will stay around until you are done. The you either send commands to the server as a response to it's messages to you, or you set up some scheduling to do your stuff. Or both.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload