[Twisted-Python] conch defer for dataReceived

Hello all. Help me please. Tell me how to wrap in Defer dataReceived. For example, I need to execute a command and send receive data in callback. The only yet I found - to use the session number sent commands and replies received
Can one example. Thanks in advance!
-- Alexey

On Jul 28, 2015, at 10:09 AM, Alexey Panyovin a@runtel.ru wrote:
Hello all. Help me please. Tell me how to wrap in Defer dataReceived. For example, I need to execute a command and send receive data in callback. The only yet I found - to use the session number sent commands and replies received
If you want to have commands and responses, you need a higher-level callback than simply dataReceived. This is what, for example, AMP <https://twistedmatrix.com/documents/current/api/twisted.protocols.amp.html https://twistedmatrix.com/documents/current/api/twisted.protocols.amp.html> is for.
-glyph

I'm use self made queue for my task. I'll try to amp.
Thanks glyph!
С уважением,

On Jul 28, 2015, at 10:02 PM, Alexey Panyovin a@runtel.ru wrote:
I'm use self made queue for my task. I'll try to amp.
Thanks glyph!
Good luck Alexey! Thanks for using Twisted!
Please feel free to ask any more questions you have about using AMP.
-glyph

Thans You!
I found same solution, but to another problem like this.
Channel class:
class SFTPChannel(channel.SSHChannel): name ='session' _sftp = defer.Deferred() # defer = def channelOpen(self, _):d =self.conn.sendRequest(self, 'subsystem', common.NS('sftp'), wantReply=True) self.conn.sftp_channel_defer = d.addCallbacks(self._cbSFTP)@defer.inlineCallbacks def _cbSFTP(self, result):self.client = FileTransferClient() self.client.makeConnection(self) self.dataReceived =self.client.dataReceived self._sftp.callback(self.client)
def get_file(self, *args): print args
Use in exteral module m = connection.sftp_channel._sftp.addCallback(connection.sftp_channel.get_file, *['./222/test.txt', '/root/freeswitch_37_17.tar']) m.addCallback(self._cbFileRCopy) m.addErrback(self._ebFileRCopy)
I think, if set some defer in SSHChannel in
def channelOpen(self, data): self.conn.sendRequest(self, 'exec', common.NS(self.command), wantReply=True).addCallback(self._gotResponse) self._chennel_defer = Defered()
and in
def dataReceived(self, data): self._chennel_defer = some_def()
But in this case one channel = one command = one respons 29.07.15 11:56, Glyph пишет:
On Jul 28, 2015, at 10:02 PM, Alexey Panyovin <a@runtel.ru mailto:a@runtel.ru> wrote: I'm use self made queue for my task. I'll try to amp. Thanks glyph!
Good luck Alexey! Thanks for using Twisted! Please feel free to ask any more questions you have about using AMP. -glyph
Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
participants (3)
-
Alexey Panyovin
-
Glyph
-
Glyph Lefkowitz