from autobahn.twisted.wamp import ApplicationSession, ApplicationRunner
class MyComponent(ApplicationSession):
def __init__(self, config = None):
ApplicationSession.__init__(self, config)
print("component created")
def onConnect(self):
print("transport connected")
self.join(self.config.realm)
def onChallenge(self, challenge):
print("authentication challenge received")
def onJoin(self, details):
print("session joined")
def onLeave(self, details):
print("session left")
def onDisconnect(self):
print("transport disconnected")
if __name__ == '__main__':
runner = ApplicationRunner(url = u"ws://address_of_wamp_router", realm = u"realm1")
runner.run(MyComponent)
Just quickly (i am on mobile): because you need to activate ws auto ping pong in the client as well so it detects broken connection quickly
Sent from Mobile (Google Nexus 5)
--
You received this message because you are subscribed to the Google Groups "Autobahn" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autobahnws+...@googlegroups.com.
To post to this group, send email to autob...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/autobahnws/90290fe4-7cab-4261-b230-269ab0ae13c1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Alex,
Thank you for the reply! Why is it that with my current configuration the router knows almost immediately when a device has been disconnected (via physical disconnection of the network cable), but the device itself remains unaware that anything has changed. Is there a ping/timeout configuration that needs to be set in Autobahn on the device side?
On Friday, July 3, 2015 at 6:18:37 PM UTC+2, Nick B wrote:Hi Alex,
Thank you for the reply! Why is it that with my current configuration the router knows almost immediately when a device has been disconnected (via physical disconnection of the network cable), but the device itself remains unaware that anything has changed. Is there a ping/timeout configuration that needs to be set in Autobahn on the device side?Tobias already hinted in his reply that this is probably the case. But I'm curious: In the current configuration you speak of above, did you have WebSocket ping-pong configured on the Crossbar node? If you did not, then I'd also be puzzled as to how the router could see the disconnect so quickly, while the client could not.
I found the autoPingTimeout and autoPingInterval options that can be set via setProtocolOptions on the client side, however, if I understand correctly this would initiate a second ping-pong round from the client to the router so that the client can close the connection if it doesn't receive a pong. To keep the overall network traffic down, I was hoping to use the ping-pong cycle initiated by the router to provide connection status for both the router and client.
I couldn't find an existing option for this, though using the autoPingTimeout as an example it was fairly straightforward to add another timeout in the WebSocketProtocol class that is reset whenever a ping is received. I can use this timeout to close the connection along with the ReconnectingClientFactory to automatically reconnect when something goes wrong. I'm not sure if there is a better or easier way to accomplish this, but it seems to be working very reliably now (at least for my crude cable yanking network failure test).
This is how TCP works.
If you plug a cable, from an endpoint this is no different than a very, very slow connection.
These things are not specific to WebSocket, WAMP, Autobahn or Crossbar.io, but simply TCP.
Am Freitag, 3. Juli 2015 19:50:46 UTC+2 schrieb Elvis Stansvik:On Friday, July 3, 2015 at 7:43:39 PM UTC+2, Elvis Stansvik wrote:On Friday, July 3, 2015 at 6:18:37 PM UTC+2, Nick B wrote:Hi Alex,
Thank you for the reply! Why is it that with my current configuration the router knows almost immediately when a device has been disconnected (via physical disconnection of the network cable), but the device itself remains unaware that anything has changed. Is there a ping/timeout configuration that needs to be set in Autobahn on the device side?Tobias already hinted in his reply that this is probably the case. But I'm curious: In the current configuration you speak of above, did you have WebSocket ping-pong configured on the Crossbar node? If you did not, then I'd also be puzzled as to how the router could see the disconnect so quickly, while the client could not.Also, as a follow-up question, I'm curious: Is there really no way for Autobahn to be notified about the underlying TCP socket being disconnected without having ping-pong configured? What if I want to be able to react more quickly than a sane ping-pong timeout value?I mean, somewhere deeper in the stack, some select() or epoll() call or something must be failing, which it should be able to detect? (sorry, my network programming knowledge is a little rusty).ElvisElvis
Good to know that automatic reconnection is in the works, in the meantime I can implement my own simple method for reconnection if I can get connection failures to be reliably detected.
Thanks,
-Nick
--
You received this message because you are subscribed to the Google Groups "Autobahn" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autobahnws+...@googlegroups.com.
To post to this group, send email to autob...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/autobahnws/205cbb5f-ecd6-48f6-8c2a-14d8450f91cc%40googlegroups.com.
transport_factory = MyClientFactory(session_factory,url = mainConfig.url, debug=True, debug_wamp=True )
# Now set the ping parameters here, factory has the protcol name.
transport_factory.autoPingInterval =5
transport_factory.autoPingTimeout =2