Exemplo n.º 1
0
	def load_all_config(self):
		if DEBUG:
			t = threading.current_thread();
			print("{0}: Loading SIB configuration".format(t))
		socketio.send(self.conn, GET_CONFIG)
		config_str = socketio.receive(self.conn)
		if DEBUG:
			print("-------------------------------------------------------------------")
			print(config_str)
			print("-------------------------------------------------------------------")
		self.config = json.loads(config_str)
Exemplo n.º 2
0
 def load_all_config(self):
     if DEBUG:
         t = threading.current_thread()
         print("{0}: Loading SIB configuration".format(t))
     socketio.send(self.conn, GET_CONFIG)
     config_str = socketio.receive(self.conn)
     if DEBUG:
         print(
             "-------------------------------------------------------------------"
         )
         print(config_str)
         print(
             "-------------------------------------------------------------------"
         )
     self.config = json.loads(config_str)
Exemplo n.º 3
0
def send(message, **kwargs):
    """Send a SocketIO message.

    This function sends a simple SocketIO message to one or more connected
    clients. The message can be a string or a JSON blob. This is a simpler
    version of ``emit()``, which should be preferred. This is a function that
    can only be called from a SocketIO event handler.

    :param message: The message to send, either a string or a JSON blob.
    :param namespace: The namespace under which the message is to be sent.
                      Defaults to the namespace used by the originating event.
                      An empty string can be used to use the global namespace.
    :param callback: Callback function to invoke with the client's
                     acknowledgement.
    :param broadcast: ``True`` to send the message to all connected clients, or
                      ``False`` to only reply to the sender of the originating
                      event.
    :param room: Send the message to all the users in the given room.
    :param include_self: ``True`` to include the sender when broadcasting or
                         addressing a room, or ``False`` to send to everyone
                         but the sender.
    """
    namespace = kwargs.get('namespace', flask.request.namespace)
    callback = kwargs.get('callback')
    broadcast = kwargs.get('broadcast')
    room = kwargs.get('room')
    if room is None and not broadcast:
        room = flask.request.sid
    include_self = kwargs.get('include_self', True)

    socketio = flask.current_app.extensions['socketio']
    return socketio.send(message, namespace=namespace, room=room,
                         include_self=include_self, callback=callback)
Exemplo n.º 4
0
def send(message, **kwargs):
    """Send a SocketIO message.

    This function sends a simple SocketIO message to one or more connected
    clients. The message can be a string or a JSON blob. This is a simpler
    version of ``emit()``, which should be preferred. This is a function that
    can only be called from a SocketIO event handler.

    :param message: The message to send, either a string or a JSON blob.
    :param namespace: The namespace under which the message is to be sent.
                      Defaults to the namespace used by the originating event.
                      An empty string can be used to use the global namespace.
    :param callback: Callback function to invoke with the client's
                     acknowledgement.
    :param broadcast: ``True`` to send the message to all connected clients, or
                      ``False`` to only reply to the sender of the originating
                      event.
    :param room: Send the message to all the users in the given room.
    :param include_self: ``True`` to include the sender when broadcasting or
                         addressing a room, or ``False`` to send to everyone
                         but the sender.
    """
    namespace = kwargs.get('namespace', flask.request.namespace)
    callback = kwargs.get('callback')
    broadcast = kwargs.get('broadcast')
    room = kwargs.get('room')
    if room is None and not broadcast:
        room = flask.request.sid
    include_self = kwargs.get('include_self', True)

    socketio = flask.current_app.extensions['socketio']
    return socketio.send(message, namespace=namespace, room=room,
                         include_self=include_self, callback=callback)
Exemplo n.º 5
0
def send(message, **kwargs):
    """Send a SocketIO message.

    This function sends a simple SocketIO message to one or more connected
    clients. The message can be a string or a JSON blob. This is a simpler
    version of ``emit()``, which should be preferred. This is a function that
    can only be called from a SocketIO event handler.

    :param message: The message to send, either a string or a JSON blob.
    :param json: ``True`` if ``message`` is a JSON blob, ``False``
                     otherwise.
    :param namespace: The namespace under which the message is to be sent.
                      Defaults to the namespace used by the originating event.
                      An empty string can be used to use the global namespace.
    :param callback: Callback function to invoke with the client's
                     acknowledgement.
    :param broadcast: ``True`` to send the message to all connected clients, or
                      ``False`` to only reply to the sender of the originating
                      event.
    :param room: Send the message to all the users in the given room.
    :param include_self: ``True`` to include the sender when broadcasting or
                         addressing a room, or ``False`` to send to everyone
                         but the sender.
    :param skip_sid: The session id of a client to ignore when broadcasting
                     or addressing a room. This is typically set to the
                     originator of the message, so that everyone except
                     that client receive the message. To skip multiple sids
                     pass a list.
    :param ignore_queue: Only used when a message queue is configured. If
                         set to ``True``, the event is emitted to the
                         clients directly, without going through the queue.
                         This is more efficient, but only works when a
                         single server process is used, or when there is a
                         single addressee. It is recommended to always leave
                         this parameter with its default value of ``False``.
    """
    json = kwargs.get('json', False)
    if 'namespace' in kwargs:
        namespace = kwargs['namespace']
    else:
        namespace = flask.request.namespace
    callback = kwargs.get('callback')
    broadcast = kwargs.get('broadcast')
    room = kwargs.get('room')
    if room is None and not broadcast:
        room = flask.request.sid
    include_self = kwargs.get('include_self', True)
    skip_sid = kwargs.get('skip_sid')
    ignore_queue = kwargs.get('ignore_queue', False)

    socketio = flask.current_app.extensions['socketio']
    return socketio.send(message,
                         json=json,
                         namespace=namespace,
                         room=room,
                         include_self=include_self,
                         skip_sid=skip_sid,
                         callback=callback,
                         ignore_queue=ignore_queue)
Exemplo n.º 6
0
	def run(self):
		if DEBUG:
			t = threading.current_thread();
			print("{0}: Updating sib server with page:{1} key:{2} value:{3}".format(t, self.page, self.key, self.value))
		conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
		conn.connect((self.domain, self.port))
		socketio.send(conn, SET_CONFIG)
		socketio.send(conn, self.page)
		socketio.send(conn, self.key)
		socketio.send(conn, json.dumps(self.value))
		conn.close()
Exemplo n.º 7
0
 def run(self):
     if DEBUG:
         t = threading.current_thread()
         print("{0}: Updating sib server with page:{1} key:{2} value:{3}".
               format(t, self.page, self.key, self.value))
     conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     conn.connect((self.domain, self.port))
     socketio.send(conn, SET_CONFIG)
     socketio.send(conn, self.page)
     socketio.send(conn, self.key)
     socketio.send(conn, json.dumps(self.value))
     conn.close()
Exemplo n.º 8
0
def send(message, **kwargs):
    """Send a SocketIO message.

    This function sends a simple SocketIO message to one or more connected
    clients. The message can be a string or a JSON blob. This is a simpler
    version of ``emit()``, which should be preferred. This is a function that
    can only be called from a SocketIO event handler.

    :param message: The message to send, either a string or a JSON blob.
    :param json: ``True`` if ``message`` is a JSON blob, ``False``
                     otherwise.
    :param namespace: The namespace under which the message is to be sent.
                      Defaults to the namespace used by the originating event.
                      An empty string can be used to use the global namespace.
    :param callback: Callback function to invoke with the client's
                     acknowledgement.
    :param broadcast: ``True`` to send the message to all connected clients, or
                      ``False`` to only reply to the sender of the originating
                      event.
    :param room: Send the message to all the users in the given room.
    :param include_self: ``True`` to include the sender when broadcasting or
                         addressing a room, or ``False`` to send to everyone
                         but the sender.
    :param ignore_queue: Only used when a message queue is configured. If
                         set to ``True``, the event is emitted to the
                         clients directly, without going through the queue.
                         This is more efficient, but only works when a
                         single server process is used, or when there is a
                         single addresee. It is recommended to always leave
                         this parameter with its default value of ``False``.
    """
    json = kwargs.get('json', False)
    if 'namespace' in kwargs:
        namespace = kwargs['namespace']
    else:
        namespace = flask.request.namespace
    callback = kwargs.get('callback')
    broadcast = kwargs.get('broadcast')
    room = kwargs.get('room')
    if room is None and not broadcast:
        room = flask.request.sid
    include_self = kwargs.get('include_self', True)
    ignore_queue = kwargs.get('ignore_queue', False)

    socketio = flask.current_app.extensions['socketio']
    return socketio.send(message, json=json, namespace=namespace, room=room,
                         include_self=include_self, callback=callback,
                         ignore_queue=ignore_queue)
Exemplo n.º 9
0
    print('Connected by', addr)

    settings_file = open(CONFIG_FILE, 'r')
    contents = settings_file.read()
    settings_file.close()

    config = json.loads(contents)

    while True:
        data = socketio.receive(conn)
        if not data:
            break
        print("received:{0}".format(data))
        if data == GET_CONFIG:
            print("received send all config command")
            socketio.send(conn, contents)
        if data == SET_CONFIG:
            print("received set config command")
            page = socketio.receive(conn)
            key = socketio.receive(conn)
            value = socketio.receive(conn)
            print("Received page:{0} key:{1} value:{2}".format(
                page, key, value))
            config['SETTINGS'][page][key] = json.loads(value)
            settings_file = open(CONFIG_FILE, 'w')
            settings_file.write(
                json.dumps(config,
                           sort_keys=True,
                           indent=4,
                           separators=(',', ': ')))
            settings_file.close()
Exemplo n.º 10
0
 def ping_message():
     socketio.send('pong')
Exemplo n.º 11
0
while True:
    conn, addr = s.accept()
    print("Connected by", addr)

    settings_file = open(CONFIG_FILE, "r")
    contents = settings_file.read()
    settings_file.close()

    config = json.loads(contents)

    while True:
        data = socketio.receive(conn)
        if not data:
            break
        print("received:{0}".format(data))
        if data == GET_CONFIG:
            print("received send all config command")
            socketio.send(conn, contents)
        if data == SET_CONFIG:
            print("received set config command")
            page = socketio.receive(conn)
            key = socketio.receive(conn)
            value = socketio.receive(conn)
            print("Received page:{0} key:{1} value:{2}".format(page, key, value))
            config["SETTINGS"][page][key] = json.loads(value)
            settings_file = open(CONFIG_FILE, "w")
            settings_file.write(json.dumps(config, sort_keys=True, indent=4, separators=(",", ": ")))
            settings_file.close()

    conn.close()