Commits

Anonymous committed d637608

Add ability to disconnect all clients

  • Participants
  • Parent commits 8296cba
  • Tags v0.7.1

Comments (0)

Files changed (5)

 SockJSProxy is a simple proxy server that proxies message from SockJS_ to a
 ZeroMQ_ socket and vise-versa.
 
+Using it you can create real-time web-based application in any backend
+language you'd like.
+
 Motivation
 ----------
 
 
 ----------
 
-The incomming messages socket is a ``PUSH`` one (by default on port ``9241``), where
+The incomming messages (i.e. sent by the client, usually a browser)
+socket is a ``PUSH`` one (by default on port ``9241``), where
 the proxy will push messages to. All messages are 3-part messages in the form of:
 
 +------------------+
 | ``data``         |
 +------------------+
 
-``message_type`` can be one of these. The other arguments are described under each
-``message_type``:
+``message_type`` can be one of those, listed below. ``session_id`` can be
+used to identify the connection. A reconnect of the
+client will result in a new session id.
 
 ``connect``
     Sent when a client connects to the server. The ``session_id`` is set,
 
 ----------
 
-The outgoing socket is a ``PULL`` one (by default on port ``9242``), where the
+The outgoing (for messages you wish to send to the client)
+socket is a ``PULL`` one (by default on port ``9242``), where the
 proxy will read messages and forward them to the SockJS client (usually a browser).
 
 The format is like the one for incomming messages:
 
 ``message``
     Send this to forward a message to a client with ``session_id``.
-    ``data`` contains the message (as bytes) for the client.
+    ``data`` contains the message for the client.
 ``disconnect``
     Disconnect the client with the given ``session_id``.
     ``data`` is discarded but *must* be present in the message as
     a part (usually empty).
+``disconnectall``
+    Disconnect all connected clients. ``session_id`` and ``data``
+    are discarded, but *must* be present in the message (leaving
+    them empty is a good idea).
 
 
 Installation
       --verbose, -v         Make the server output more information - useful for
                             debugging
 
+Stopping the server
+-------------------
+When the server is running in the foreground - pressing ``Ctrl+C`` would stop it.
+If you use something like ``nohup`` do deamonize it - send it ``SIGTERM``
+(see ``man kill`` for more info) and it will gracefully stop.
+
 
 Samples
 -------
 
 Changelog
 ---------
+0.7.1
+  - Added ``disconnectall`` capability to force all clients
+    to disconnect.
 0.7
   - Switch from ``PUB/SUB`` socket pair to ``PUSH/PULL``.
   - Add support to force the client to disconnect.
 #!/usr/bin/env python
 
-"""SockJSProxy - Proxy SockJS message to/from ZeroMQ PUSH/PULL sockets.
+"""SockJSProxy - Proxy SockJS messages to/from ZeroMQ PUSH/PULL sockets.
 
 See the `samples/datereply-sjp.py` file for an example client.
 

File sockjsproxy/__init__.py

-VERSION = '0.7.0'
+VERSION = '0.7.1'

File sockjsproxy/samples/datereply-sjp.py

                 out_socket.send_multipart(['message',
                                            session_id,
                                            'The time now is: ' + str(datetime.datetime.now())])
-                out_socket.send_multipart(['disconnect',
-                                           session_id,
-                                           ''])
+                out_socket.send_multipart(['disconnect', session_id, ''])
+                # out_socket.send_multipart(['disconnectall', '', ''])
     except KeyboardInterrupt:
         pass
 

File sockjsproxy/sockjsproxy.py

             self.frontend.send(session_id, message)
         elif command == 'disconnect':
             self.frontend.close(session_id)
+        elif command == 'disconnectall':
+            self.frontend.close_all()
         else:
             log.warn("Invalid command %s", command)
 
 
         connection.close()
 
+    def close_all(self):
+        for c in self.sessions.values():
+            c.close()
+
 
 class SockJSProxy(object):
     def collect_args(self):