crossbario / autobahn-python

WebSocket and WAMP in Python for Twisted and asyncio
https://crossbar.io/autobahn
MIT License
2.48k stars 768 forks source link

Websocket: send binary message from memoryview() or bytes-like object #877

Open aronhelser opened 7 years ago

aronhelser commented 7 years ago

I have a python Twisted webserver that communicates with a JS client over websockets. I would like to send binary messages from a memoryview() - but autobahn has an assert() that the source of sendMessage must be type == byte.

Could sendMessage accept memoryview, or any 'bytes-like' object?

oberstet commented 7 years ago

Yeah, probably.

Main issue is how to test for "bytes-like object" without introducing any overhead

On a side note, I am wondering about https://github.com/Kitware/wslink/blob/master/design.md - there are plain wrong statements there (like "WAMP only supports base64-encoded binary objects."), and I am wondering about the general motivation ..

aronhelser commented 7 years ago

Does the current assert() introduce overhead? I guess you could just explicitly add tests for memoryview and bytearray, and be done.

About the side note - the design document is my simplified, initial understanding. I would be happy to correct any wrong statements. I found Msgpack serializer later, which does binary transfer, correct? My understanding is that it is enabled for the entire session? We're sending some binary and some json messages.

The main motivation for wslink is managing the weird lifecycle of ParaViewWeb connections - a server process per user that must clean up when the user disconnects. Plus simplification from removing the router.

oberstet commented 7 years ago

I guess you could just explicitly add tests for memoryview and bytearray, and be done.

Yes, but then it won't work for any byte like thingy.

Rgd serializers: Crossbar.io supports JSON, MessagePack, CBOR and UBJSON, and it can transparently translate between clients using different serializers.

Crossbar.io, AutobahnJS and AutobahnPython also support binary values in JSON using automatic base64 encoding/decoding and a special NUL byte marker byte at the beginning.

Other webservers - WAMP has been implemented elsewhere, but in JavaScript the only implementations require autobahn's router, crossbar.io. It would be great to support Tornado and CherryPy as alternative webservers to Twisted/autobahn.

I cannot parse this para. AutobahnJS works with any WAMP router, and that router does not even have to implement WAMP-over-WebSocket, and hence WebSocket at all! WAMP can run over raw TCP and HTTP Longpoll too. And AutobahnJS supports that.

Then, Crossbar.io should be treated as a black-box server software, pretty much like Nginx for example. Hence, there is no point in "supporting Tornado/CheerPy".

Tbh, I don't understand the "issues" at all, but anyways, I'd say, could luck reinventing WAMP/Crossbar.io on top of JSON-RPC or similar;)