
    i                     .    S SK r SSKJr   " S S\5      rg)    N   )PubSubManagerc                   J   ^  \ rS rSrSrSr  S	U 4S jjrS rS rS r	Sr
U =r$ )

ZmqManager   aW  zmq based client manager.

NOTE: this zmq implementation should be considered experimental at this
time. At this time, eventlet is required to use zmq.

This class implements a zmq backend for event sharing across multiple
processes. To use a zmq backend, initialize the :class:`Server` instance as
follows::

    url = 'zmq+tcp://hostname:port1+port2'
    server = socketio.Server(client_manager=socketio.ZmqManager(url))

:param url: The connection URL for the zmq message broker,
            which will need to be provided and running.
:param channel: The channel name on which the server sends and receives
                notifications. Must be the same in all the servers.
:param write_only: If set to ``True``, only initialize to emit events. The
                   default of ``False`` initializes the class for emitting
                   and receiving. A write-only instance can be used
                   independently of the server to emit to clients from an
                   external process.
:param logger: a custom logger to log it. If not given, the server logger
               is used.
:param json: An alternative JSON module to use for encoding and decoding
             packets. Custom json modules must have ``dumps`` and ``loads``
             functions that are compatible with the standard library
             versions. This setting is only used when ``write_only`` is set
             to ``True``. Otherwise the JSON module configured in the
             server is used.

A zmq message broker must be running for the zmq_manager to work.
you can write your own or adapt one from the following simple broker
below::

    import zmq

    receiver = zmq.Context().socket(zmq.PULL)
    receiver.bind("tcp://*:5555")

    publisher = zmq.Context().socket(zmq.PUB)
    publisher.bind("tcp://*:5556")

    while True:
        publisher.send(receiver.recv())
zmqc                   >  SSK Jn  [        R
                  " S5      nUR                  S5      (       a  UR                  U5      (       d  [        SU-   5      e[        TU ]%  X#UUS9  UR                  SS	5      nUR                  S
5      u  pUR                  S5      S   n
UR                  X5      nUR                  5       R                  UR                  5      nUR                  U5        UR                  5       R                  UR                   5      nUR#                  UR$                  S	5        UR                  U5        Xl        Xl        X l        g ! [         a    [        S5      ef = f)Nr   )r   zJzmq package is not installed (Run "pip install pyzmq" in your virtualenv).z
:\d+\+\d+$z
zmq+tcp://zunexpected connection string: )channel
write_onlyloggerjsonzzmq+ +:)eventlet.greenr   ImportErrorRuntimeErrorrecompile
startswithsearchsuper__init__replacesplitContextsocketPUSHconnectSUBsetsockopt_string	SUBSCRIBEsinksubr
   )selfurlr
   r   r   r   r   rsink_urlsub_port	sink_portsub_urlr$   r%   	__class__s                 Q/home/admin/cozy_coffee/venv/lib/python3.13/site-packages/socketio/zmq_manager.pyr   ZmqManager.__init__6   s5   	/* JJ}%|,,#?#EFF" 	 	$kk&"%"yy~NN3'+	""97{{}##CHH-Xkkm""377+cmmR0G	3  	/  . / /	/s   E E+c                     U R                   R                  SU R                  US.5      R                  5       nU R                  R                  U5      $ )Nmessage)typer
   data)r   dumpsr
   encoder$   send)r&   r3   packed_datas      r.   _publishZmqManager._publishU   sG    iioo!<<
 &( 	 yy~~k**    c              #   R   #     U R                   R                  5       nUb  Uv   M#  7f)N)r%   recv)r&   responses     r.   
zmq_listenZmqManager.zmq_listen_   s'     xx}}H# s   %'c              #   H  #    U R                  5        Hz  n[        U[        5      (       a   U R                  R	                  U5      n[        U[        5      (       d  MK  US   S:X  d  MV  US   U R                  :X  d  Mk  SU;   d  Ms  US   v   M|     g ! [
         a     NWf = f7f)Nr2   r1   r
   r3   )r>   
isinstancebytesr   loads	Exceptiondictr
   )r&   r1   s     r.   _listenZmqManager._listene   s     (G'5))"iioog6G '4((FOy0I&$,,6g%fo% ) 	 ! s@   )B"BB"B")B">B"B"
BB"BB")r
   r$   r%   )zzmq+tcp://localhost:5555+5556socketioFNN)__name__
__module____qualname____firstlineno____doc__namer   r8   r>   rF   __static_attributes____classcell__)r-   s   @r.   r   r      s/    ,Z DDN59>+ r:   r   )r   pubsub_managerr   r    r:   r.   <module>rS      s    	 )k kr:   