MCPcopy
hub / github.com/miguelgrinberg/Flask-SocketIO / send

Method send

src/flask_socketio/__init__.py:524–562  ·  view source on GitHub ↗

Send a server-generated 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 function can be used outside

(self, data, json=False, namespace=None, to=None,
             callback=None, include_self=True, skip_sid=None, **kwargs)

Source from the content-addressed store, hash-verified

522 **kwargs)
523
524 def send(self, data, json=False, namespace=None, to=None,
525 callback=None, include_self=True, skip_sid=None, **kwargs):
526 """Send a server-generated SocketIO message.
527
528 This function sends a simple SocketIO message to one or more connected
529 clients. The message can be a string or a JSON blob. This is a simpler
530 version of ``emit()``, which should be preferred. This function can be
531 used outside of a SocketIO event context, so it is appropriate to use
532 when the server is the originator of an event.
533
534 :param data: The message to send, either a string or a JSON blob.
535 :param json: ``True`` if ``message`` is a JSON blob, ``False``
536 otherwise.
537 :param namespace: The namespace under which the message is to be sent.
538 Defaults to the global namespace.
539 :param to: Send the message to all the users in the given room, or to
540 the user with the given session ID. If this parameter is not
541 included, the event is sent to all connected users.
542 :param include_self: ``True`` to include the sender when broadcasting
543 or addressing a room, or ``False`` to send to
544 everyone but the sender.
545 :param skip_sid: The session id of a client to ignore when broadcasting
546 or addressing a room. This is typically set to the
547 originator of the message, so that everyone except
548 that client receive the message. To skip multiple sids
549 pass a list.
550 :param callback: If given, this function will be called to acknowledge
551 that the client has received the message. The
552 arguments that will be passed to the function are
553 those provided by the client. Callback functions can
554 only be used when addressing an individual client.
555 """
556 skip_sid = flask.request.sid if not include_self else skip_sid
557 if json:
558 self.emit('json', data, namespace=namespace, to=to,
559 skip_sid=skip_sid, callback=callback, **kwargs)
560 else:
561 self.emit('message', data, namespace=namespace, to=to,
562 skip_sid=skip_sid, callback=callback, **kwargs)
563
564 def close_room(self, room, namespace=None):
565 """Close a room.

Callers 11

test_sendMethod · 0.45
test_send_jsonMethod · 0.45
test_send_namespaceMethod · 0.45
test_managed_sessionMethod · 0.45
test_ackMethod · 0.45
test_noackMethod · 0.45
test_send_class_basedMethod · 0.45
sendFunction · 0.45

Calls 1

emitMethod · 0.95

Tested by 10

test_sendMethod · 0.36
test_send_jsonMethod · 0.36
test_send_namespaceMethod · 0.36
test_managed_sessionMethod · 0.36
test_ackMethod · 0.36
test_noackMethod · 0.36
test_send_class_basedMethod · 0.36