Discussion:
[Twisted-Python] conch defer for dataReceived
Alexey Panyovin
2015-07-28 17:09:42 UTC
Permalink
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
Glyph Lefkowitz
2015-07-29 00:40:18 UTC
Permalink
Post by Alexey Panyovin
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
Alexey Panyovin
2015-07-29 05:02:04 UTC
Permalink
I'm use self made queue for my task.
I'll try to amp.

Thanks glyph!

С уважеМОеЌ,
--
ПаМевОМ Алексей
КПЌЌерческОй ЎОректПр

ООО РаМтел

e-mail: ***@runtel.ru
Tel: +7 (495) 134-30-60 (1011)
Tel: +7 (906) 680-04-04
Post by Glyph Lefkowitz
Post by Alexey Panyovin
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>
is for.
-glyph
_______________________________________________
Twisted-Python mailing list
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Glyph
2015-07-29 08:56:29 UTC
Permalink
Post by Alexey Panyovin
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
Alexey Panyovin
2015-07-29 09:09:23 UTC
Permalink
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,
Post by Glyph
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
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Loading...