Publish zip files and receive zip files by subscribing to it

Hi,
I am trying to send a file using autobahn-python and crossbar.io as a WAMP server(running as a default docker instance), I was wondering if it’s possible to publish a compressed file over a stream and also get. the same file by subscribing to it.

publisher code,

import os
import six
import argparse

import txaio
txaio.use_asyncio()

from autobahn.asyncio.wamp import ApplicationSession, ApplicationRunner
from autobahn.wamp.types import SubscribeOptions
from  autobahn.wamp.serializer import MsgPackSerializer,CBORObjectSerializer
from autobahn.wamp.types import PublishOptions
import asyncio
from autobahn.wamp.exception import ApplicationError
import mmap


class ClientSession(ApplicationSession):

    async def onJoin(self, details):
        print('session joined', details)
        with open('venv.zip', 'rb') as f:
            m = mmap.mmap(f.fileno(), 0, prot=mmap.PROT_READ)

        async def stream_heartbeats(self):
            counter=1
            print(counter)
            while True:
                counter=counter+1
                try:
                    publication = await self.publish(u'com.intusurg.xi.systems.{}.heartbeat'.format("vb8188"),{"data":m},options=PublishOptions(acknowledge=True, exclude_me=False))
                except ApplicationError as e:
                    print(e.args)
                print("heartbeat id = {}".format(publication))
                await asyncio.sleep(1)
        asyncio.ensure_future(stream_heartbeats(self))
    
    def onDisconnect(self):
        print("Disconnected!!!")


if __name__ == '__main__':
    parser = argparse.ArgumentParser()

    parser.add_argument('-d',
                        '--debug',
                        action='store_true',
                        help='Enable debug output.')

    parser.add_argument('--url',
                        dest='url',
                        type=six.text_type,
                        default="rs://localhost:8080",
                        help='The router URL (default: "rs://localhost:8080").')

    parser.add_argument('--realm',
                        dest='realm',
                        type=six.text_type,
                        default="realm1",
                        help='The realm to join (default: "realm1").')

    args = parser.parse_args()

    # start logging
    if args.debug:
        txaio.start_logging(level='debug')
    else:
        txaio.start_logging(level='info')

    extra = {
    }
    serializer = [MsgPackSerializer()]
    runner = ApplicationRunner(
                url=args.url,
                realm=args.realm,
                serializers=serializer,
                extra=extra
            )
    runner.run(ClientSession)

traceback::

Packer(**kwargs).pack(o)
  File "msgpack/_packer.pyx", line 284, in msgpack._cmsgpack.Packer.pack
  File "msgpack/_packer.pyx", line 290, in msgpack._cmsgpack.Packer.pack
  File "msgpack/_packer.pyx", line 287, in msgpack._cmsgpack.Packer.pack
  File "msgpack/_packer.pyx", line 263, in msgpack._cmsgpack.Packer._pack
  File "msgpack/_packer.pyx", line 263, in msgpack._cmsgpack.Packer._pack
  File "msgpack/_packer.pyx", line 234, in msgpack._cmsgpack.Packer._pack
  File "msgpack/_packer.pyx", line 281, in msgpack._cmsgpack.Packer._pack
TypeError: can not serialize 'mmap.mmap' object

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/coroutines.py", line 126, in send
    return self.gen.send(value)
  File "rs_publisher.py", line 30, in stream_heartbeats
    publication = await self.publish(u'com.intusurg.xi.systems.{}.heartbeat'.format("vb8188"),{"data":m},options=PublishOptions(acknowledge=True, exclude_me=False))
  File "/Users/vchauhan/playground/test/venv/lib/python3.6/site-packages/autobahn/wamp/protocol.py", line 1460, in publish
    raise e
  File "/Users/vchauhan/playground/test/venv/lib/python3.6/site-packages/autobahn/wamp/protocol.py", line 1456, in publish
    self._transport.send(msg)
  File "/Users/vchauhan/playground/test/venv/lib/python3.6/site-packages/autobahn/asyncio/rawsocket.py", line 311, in send
    .format(e))
autobahn.wamp.exception.SerializationError: WampRawSocketProtocol: unable to serialize WAMP application payload (can not serialize 'mmap.mmap' object)

^CDisconnected!!!
(venv) ➜  test python3 rs_publisher.py
2019-12-16T17:57:32 ApplicationSession started.
session joined
SessionDetails(realm=<realm1>,
               session=4827374686549839,
               authid=<X5G4-KACC-369Y-W5JN-UXAE-PQ76>,
               authrole=<anonymous>,
               authmethod=anonymous,
               authprovider=static,
               authextra={'x_cb_node_id': None, 'x_cb_peer': 'tcp4:172.17.0.1:35356', 'x_cb_pid': 16},
               serializer=<msgpack>,
               resumed=None,
               resumable=None,
               resume_token=None)
1
2019-12-16T17:57:32 Task exception was never retrieved
future: <Task finished coro=<ClientSession.onJoin.<locals>.stream_heartbeats() done, defined at rs_publisher.py:24> exception=SerializationError("WampRawSocketProtocol: unable to serialize WAMP application payload (can not serialize 'mmap.mmap' object)",) created at rs_publisher.py:35>
source_traceback: Object created at (most recent call last):
  File "rs_publisher.py", line 78, in <module>
    runner.run(ClientSession)
  File "/Users/vchauhan/playground/test/venv/lib/python3.6/site-packages/autobahn/asyncio/wamp.py", line 274, in run
    loop.run_forever()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 427, in run_forever
    self._run_once()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 1432, in _run_once
    handle._run()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/events.py", line 145, in _run
    self._callback(*self._args)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/coroutines.py", line 126, in send
    return self.gen.send(value)
  File "rs_publisher.py", line 35, in onJoin
    asyncio.ensure_future(stream_heartbeats(self))
Traceback (most recent call last):
  File "/Users/vchauhan/playground/test/venv/lib/python3.6/site-packages/autobahn/asyncio/rawsocket.py", line 307, in send
    payload, _ = self._serializer.serialize(msg)
  File "/Users/vchauhan/playground/test/venv/lib/python3.6/site-packages/autobahn/wamp/serializer.py", line 98, in serialize
    return msg.serialize(self._serializer), self._serializer.BINARY
  File "/Users/vchauhan/playground/test/venv/lib/python3.6/site-packages/autobahn/wamp/message.py", line 525, in serialize
    self._serialized[serializer] = serializer.serialize(self.marshal())
  File "/Users/vchauhan/playground/test/venv/lib/python3.6/site-packages/autobahn/wamp/serializer.py", line 359, in serialize
    data = _packb(obj)
  File "/Users/vchauhan/playground/test/venv/lib/python3.6/site-packages/autobahn/wamp/serializer.py", line 314, in <lambda>
    _packb = lambda obj: msgpack.packb(obj, use_bin_type=True)  # noqa
  File "/Users/vchauhan/playground/test/venv/lib/python3.6/site-packages/msgpack/__init__.py", line 46, in packb
    return Packer(**kwargs).pack(o)
  File "msgpack/_packer.pyx", line 284, in msgpack._cmsgpack.Packer.pack
  File "msgpack/_packer.pyx", line 290, in msgpack._cmsgpack.Packer.pack
  File "msgpack/_packer.pyx", line 287, in msgpack._cmsgpack.Packer.pack
  File "msgpack/_packer.pyx", line 263,

You can certainly use publish() and subscribe() to deliver arbitrary bytes (but would have to actually put those bytes in the payload, instead of a mmap instance). However, for this use-case it might be better to use a method-call along with progressive-results if the file is large (using progressive results allows to deliver chunks of the file incrementally). See: https://crossbar.io/docs/Progressive-Call-Results/