New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clientConnectionFailed() and other ClientFactory methods are not called for WAMP applications. #389
Comments
Thanks for the nice summary! My opinion is to subclass For WAMP there's conceptually two sub-cases on the "re-connect" side, too: if the client disconnected "on purpose" (e.g. called So what we want from this ticket are the building-blocks so that a Twisted user can express their desired retry and/or reconnect logic to Autobahn. |
@mkohler Thanks for the wrapup! We need to address this soon. AutobahnJS has a quite elaborated reconnection behavior - and we need that in AutobahnPython too.
Yep. This has mostly historic reasons. Essentially, all the examples should use endpoints.
As you point out, it may be clearer to subclass In essence, I agree with @meejah : > My opinion is to subclass Factory and provide an Autobahn/WAMP-specific reconnect options. For the options and the (re-)connect logic: see AutobahnJS https://github.com/tavendo/AutobahnJS/blob/master/package/lib/connection.js#L90 |
related to #295 |
As the tx base classes
I guess it's save when we just subclass The reconnection thing is already worked on in different tickets. |
That's right, but the change I made has consequences #500 Essentially, it breaks |
@mkohler So while it's confusing, subclassing @meejah I'd say, backout the change. The only alternative I see is officially dropping support for using WebSocketClientFactory with connectTCP at all. Plus then changing most of our own WebSocket examples. Would that be better? |
Alright, I've backed out the change. I should have looked more closely. There is no issue anyway:
Correct. But the origin of this is Twisted going from old world (connectTCP) to new world (endpoints). Hence: won't fix (here) |
Since "the future is endpoints", yes that sounds like the right approach (changing the examples, but keeping |
Background
The old way to have a reactor call
connect
for you was to subclasstwisted.internet.ClientFactory
, create an instance of your class, and pass that toreactor.connectTCP
.Later versions of Twisted added the endpoints API, which provides a different way of having the reactor call
connect
. With the endpoints API, you passtwisted.internet.endpoints.clientFromString
a string encoding the destinations (protocol, IP address, port) and you are returned a client object, which has aconnect
method. Then you call theconnect
method, passing it a transport factory.According to the Twisted documentation, the endpoints API is preferred over
ClientFactory
for new code.Autobahn, ClientFactory, and the Endpoints API
In general, the twisted/websocket examples use the
ClientFactory
/connectTCP
API.By contrast, the twisted/wamp examples use the endpoints API directly, or indirectly, by using
autobahn.twisted.wamp.ApplicationRunner
.The Problem
autobahn.twisted.websocket.WebSocketClientFactory
, which is used by WAMP applications, subclassesClientFactory
. However, sinceApplicationRunner
uses the endpoints API to make connections, theClientFactory
methods (startedConnecting
,clientConnectionFailed
, andclientConnectionLost
) are never called, which is surprising and confusing.According to the note "If you've used ClientFactory before..." on this page, it is the intended behavior of the endpoints API to not call
ClientFactory
methods.Possible Solutions
autobahn.twisted.websocket.WebSocketClientFactory
subclasst.i.Factory
instead oft.i.ClientFactory
.Given that the
ClientFactory
methods are not called for WAMP applications, it would be more clear ifautobahn.twisted.websocket.WebSocketClientFactory
subclassedtwisted.internet.factory
instead oftwisted.internet.ClientFactory
.ApplicationRunner
to useClientFactory
instead of the endpoints API.This would enable WAMP applications access to functionality that isn't
yet available with the endpoints API, e.g. https://twistedmatrix.com/trac/ticket/4735
The text was updated successfully, but these errors were encountered: