WAMP twisted: clientConnectionLost does not get called

#1

Hi,

I try to reconnect after the connection gets somehow lost (To test I’m just pulling the ethernet-cable).

The problem is that clientConnectionLost doesn’t get called before I close the program (ctrl+c).

You can see that clearly in the log:

2015-03-22 17:15:26+0100 [-] Log opened.

2015-03-22 17:15:26+0100 [-] Starting factory <main.MyClientFactory instance at 0x10e92f8c0>

^C2015-03-22 17:15:39+0100 [-] Received SIGINT, shutting down.

2015-03-22 17:15:39+0100 [WampWebSocketClientProtocol,client] *************************************

2015-03-22 17:15:39+0100 [WampWebSocketClientProtocol,client] Connection Lost

2015-03-22 17:15:39+0100 [WampWebSocketClientProtocol,client] reason: [Failure instance: Traceback (failure with no frames): <class ‘twisted.internet.error.ConnectionLost’>: Connection to the other side was lost in a non-clean fashion: Connection lost.

2015-03-22 17:15:39+0100 [WampWebSocketClientProtocol,client] ]

2015-03-22 17:15:39+0100 [WampWebSocketClientProtocol,client] *************************************

2015-03-22 17:15:39+0100 [WampWebSocketClientProtocol,client] <twisted.internet.tcp.Connector instance at 0x10e93c710> will retry in 2 seconds

2015-03-22 17:15:39+0100 [WampWebSocketClientProtocol,client] Stopping factory <main.MyClientFactory instance at 0x10e92f8c0>

2015-03-22 17:15:39+0100 [-] Main loop terminated.

``

Here’s my code:

# Copied from https://gist.github.com/DenJohX/e6d0864738da10cb9685 -> DenJohX

# Slightly modified

 

import sys

from twisted.python import log

from twisted.internet import reactor

from twisted.internet.protocol import ReconnectingClientFactory

 

from autobahn.websocket.protocol import parseWsUrl

from autobahn.twisted import wamp, websocket

from autobahn.wamp import types

 

 

class MyFrontendComponent(wamp.ApplicationSession):

    def onJoin(self, details):

        pass

 

    def onDisconnect(self):

        pass

 

 

class MyClientFactory(websocket.WampWebSocketClientFactory, ReconnectingClientFactory):

    maxDelay = 30

 

    def clientConnectionFailed(self, connector, reason):

        print "*************************************"

        print "Connection Failed"

        print "reason:", reason

        print "*************************************"

        ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)

 

    def clientConnectionLost(self, connector, reason):

        print "*************************************"

        print "Connection Lost"

        print "reason:", reason

        print "*************************************"

        ReconnectingClientFactory.clientConnectionLost(self, connector, reason)

 

 

if __name__ == '__main__':

    ## 0) start logging to console

    log.startLogging(sys.stdout)

 

    ## 1) create a WAMP application session factory

    component_config = types.ComponentConfig(realm="realm1")

    session_factory = wamp.ApplicationSessionFactory(config=component_config)

    session_factory.session = MyFrontendComponent

 

    ## 2) create a WAMP-over-WebSocket transport client factory

    url = u"ws://url.com:8080/ws"

    transport_factory = MyClientFactory(session_factory, url=url, debug=False)

 

    ## 3) start the client from a Twisted endpoint

    isSecure, host, port, resource, path, params = parseWsUrl(url)

    transport_factory.host = host

    transport_factory.port = port

    websocket.connectWS(transport_factory)

 

    ## 4) now enter the Twisted reactor loop

    reactor.run()

``

https://gist.github.com/jegger/d82a1197bd81b0daa1b3

Do you have any hints?

Thanks,
0 Likes