0

I'm working on a python3.3 client: I need to connect to a ratchet-wamp php server and subscribe to a topic. I've installed asyncio and autobahn.

I follow this example https://github.com/tavendo/AutobahnPython/blob/master/examples/asyncio/wamp/beginner/client.py but it doesn't work, after the handshake the tcp connection drops.

Activating all the debug the result is:

[('debug', True, 'WampWebSocketClientFactory'),
 ('debugCodePaths', False, 'WampWebSocketClientFactory'),
 ('logOctets', True, 'WampWebSocketClientFactory'),
 ('logFrames', True, 'WampWebSocketClientFactory'),
 ('trackTimings', False, 'WampWebSocketClientFactory'),
 ('allowHixie76', False, 'WampWebSocketClientFactory'),
 ('utf8validateIncoming', True, 'WampWebSocketClientFactory'),
 ('applyMask', True, 'WampWebSocketClientFactory'),
 ('maxFramePayloadSize', 0, 'WampWebSocketClientFactory'),
 ('maxMessagePayloadSize', 0, 'WampWebSocketClientFactory'),
 ('autoFragmentSize', 0, 'WampWebSocketClientFactory'),
 ('failByDrop', True, 'WampWebSocketClientFactory'),
 ('echoCloseCodeReason', False, 'WampWebSocketClientFactory'),
 ('openHandshakeTimeout', 5, 'WampWebSocketClientFactory'),
 ('closeHandshakeTimeout', 1, 'WampWebSocketClientFactory'),
 ('tcpNoDelay', True, 'WampWebSocketClientFactory'),
 ('autoPingInterval', 0, 'WampWebSocketClientFactory'),
 ('autoPingTimeout', 0, 'WampWebSocketClientFactory'),
 ('autoPingSize', 4, 'WampWebSocketClientFactory'),
 ('version', 18, 'WampWebSocketClientFactory'),
 ('acceptMaskedServerFrames', False, 'WampWebSocketClientFactory'),
 ('maskClientFrames', True, 'WampWebSocketClientFactory'),
 ('serverConnectionDropTimeout', 1, 'WampWebSocketClientFactory'),
 ('perMessageCompressionOffers', [], 'WampWebSocketClientFactory'),
 ('perMessageCompressionAccept',
  <function WebSocketClientFactory.resetProtocolOptions.<locals>.<lambda> at 0x00000000031619D8>,
  'WampWebSocketClientFactory')]
connection to 192.168.100.218:44444 established
TX Octets to 192.168.100.218:44444 : sync = False, octets = b'474554202f20485454502f312e310d0a557365722d4167656e743a204175746f6261686e507974686f6e2f302e392e310d0a486f73743a206c6f63616c686f73743a38300d0a557067726164653a20576562536f636b65740d0a436f6e6e656374696f6e3a20557067726164650d0a507261676d613a206e6f2d63616368650d0a43616368652d436f6e74726f6c3a206e6f2d63616368650d0a5365632d576562536f636b65742d4b65793a204f4d753955674b565442697375665741796246332b413d3d0d0a5365632d576562536f636b65742d50726f746f636f6c3a2077616d702e322e6a736f6e2e626174636865642c77616d702e322e6a736f6e0d0a5365632d576562536f636b65742d56657273696f6e3a2031330d0a0d0a'
GET / HTTP/1.1

User-Agent: AutobahnPython/0.9.1

Host: localhost:80

Upgrade: WebSocket

Connection: Upgrade

Pragma: no-cache

Cache-Control: no-cache

Sec-WebSocket-Key: OMu9UgKVTBisufWAybF3+A==

Sec-WebSocket-Protocol: wamp.2.json.batched,wamp.2.json

Sec-WebSocket-Version: 13




RX Octets from 192.168.100.218:44444 : octets = b'485454502f312e312031303120537769746368696e672050726f746f636f6c730d0a557067726164653a20776562736f636b65740d0a436f6e6e656374696f6e3a20557067726164650d0a5365632d576562536f636b65742d4163636570743a2049332f372f7745784b626d65705975796835444177384d683936593d0d0a582d506f77657265642d42793a20526174636865742f302e322e370d0a0d0a81265b302c2235343235363164383232613866222c312c22526174636865745c2f302e322e37225d'
received HTTP response:

b'HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: I3/7/wExKbmepYuyh5DAw8Mh96Y=\r\nX-Powered-By: Ratchet/0.2.7\r\n\r\n'


received HTTP status line in opening handshake : HTTP/1.1 101 Switching Protocols
received HTTP headers in opening handshake : {'connection': 'Upgrade', 'upgrade': 'websocket', 'sec-websocket-accept': 'I3/7/wExKbmepYuyh5DAw8Mh96Y=', 'x-powered-by': 'Ratchet/0.2.7'}
WAMP-over-WebSocket transport lost: wasClean = False, code = 1006, reason = 'connection was closed uncleanly (I failed the WebSocket connection by dropping the TCP connection)'
Traceback (most recent call last):
  File "C:\Python33\lib\site-packages\autobahn-0.9.1-py3.3.egg\autobahn\wamp\websocket.py", line 75, in onClose
    self._session.onClose(wasClean)
AttributeError: 'WampWebSocketClientProtocol' object has no attribute '_session'
connection to 192.168.100.218:44444 lost

The server is ok (another application it is connected with it). Any suggestion? Thx!

Emile Cormier
  • 28,391
  • 15
  • 94
  • 122
fryederich
  • 13
  • 3

2 Answers2

1

fryederich,

Ratchet supports WAMP v1 not v2. The Autobahn client you're trying to use is for WAMP v2. For a compatible client you'll need to use Autobahn Python 0.8.5.

If you do end up needing a WAMPv2 compatible PHP library, take a look at Thruway (I'm one of the developers on that project). It works with the latest versions of Autobahn Python and JS.

daviddan
  • 416
  • 2
  • 8
0

As Daviddan says, the problem was the different version of Wamp (asyncio uses V2, Ratchet V1). I could change neither the server (wamp V1) nor the python version of client (for python 3.3 I didn't found a wamp V1 implementation): so using a simple websocket python module ("websocket"), I implemented the wamp V1 protocol that is quite simple (here the V1 specifications).

fryederich
  • 13
  • 3