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 Languagebased 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 all

Basic 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:

Delete the channel:

Scope  (2)

Send a message as an association:

Send as a rule or a list of rules:

Send an arbitrary Wolfram Language code:

Send the current notebook:

Clean up:

Create a channel to transmit data encoded as a JSON string:

Start listening on the channel:

Encode and send some data:

Retrieve and decode the received data:

Clean up:

Applications  (1)

A channel listener that receives a compressed notebook and opens it in a new window:

Create a notebook and send it to the channel:

The received notebook:

Clean up:

Properties & Relations  (2)

Messages sent with ChannelSend can be received by listeners created with ChannelListen:

Clean up:

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:

Clean up:

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:

Clean up:

Wolfram Research (2016), ChannelSend, Wolfram Language function, https://reference.wolfram.com/language/ref/ChannelSend.html (updated 2020).

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

BibTeX

@misc{reference.wolfram_2024_channelsend, author="Wolfram Research", title="{ChannelSend}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/ChannelSend.html}", note=[Accessed: 21-December-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_channelsend, organization={Wolfram Research}, title={ChannelSend}, year={2020}, url={https://reference.wolfram.com/language/ref/ChannelSend.html}, note=[Accessed: 21-December-2024 ]}