ChannelSend
ChannelSend[channel,msg]
sends the specified message msg to the specified channel.
Details and Options
- In ChannelSend[channel,…], channel can be specified as a channel object or in any of the forms used inside ChannelObject.
- The message msg can be any expression.
- With the default setting $AllowExternalChannelFunctions=False, ChannelSend[channel,…] works only for certified channels and for channels owned by you.
- All messages are internally serialized to WXF before being transmitted through the channel broker server, with the exception of bare strings, which are transmitted as is.
- Any non-Wolfram Language–based channel broker clients that may be released in the future are likely to only support string messages, so if you desire to make your program's messages forward compatible with such clients, it is suggested to encode them in a language-independent string format such as JSON or XML.
- ChannelSend only blocks until the message has been transmitted to the broker; it does not wait for the broker to acknowledge receipt.
Examples
open allclose allBasic Examples (1)
Start listening on a channel and send a message on the channel:
Send a message on the channel:
The message is available from the listener, in the form specified for the ChannelListener object:
Scope (2)
Send a message as an association:
Send as a rule or a list of rules:
Send an arbitrary Wolfram Language code:
Create a channel to transmit data encoded as a JSON string:
Start listening on the channel:
Applications (1)
Properties & Relations (2)
Messages sent with ChannelSend can be received by listeners created with ChannelListen:
For security purposes, a message sent by ChannelSend might be held in unevaluated form by channel listeners, depending on its content.
The myFunction call is read wrapped in HoldComplete:
Possible Issues (1)
Messages sent to a channel will not be immediately available from listeners connected to the channel, as ChannelSend returns asynchronously:
Send a message and immediately try to retrieve it from the listener:
Introducing a short pause after sending the message allows time for the message to be received by the listener:
A While loop can also be used to wait until a message is available from the listener:
Text
Wolfram Research (2016), ChannelSend, Wolfram Language function, https://reference.wolfram.com/language/ref/ChannelSend.html (updated 2020).
CMS
Wolfram Language. 2016. "ChannelSend." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/ChannelSend.html.
APA
Wolfram Language. (2016). ChannelSend. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ChannelSend.html