WOLFRAM

ChannelListen[channel]

starts listening on the specified channel.

ChannelListen[channel,func]

applies func to the association corresponding to each message received on the channel.

ChannelListen[channel,None]

stores each message received on the channel, without applying any function.

listens on the specified URL, storing messages received, without requiring an explicit channel to exist on the channel broker.

Details and Options

  • ChannelListen[] gives a ChannelListener object.
  • In ChannelListen[channel,], channel can be specified as a channel object or in any of the forms used inside ChannelObject.
  • ChannelListen[channel] is equivalent to ChannelListen[channel,Automatic].
  • If specified in ChannelListen[channel,func], func overrides the "MessageReceived" handler of channel. It is called with the association containing the following elements:
  • "Message"contents of the message
    "MessageID"unique message ID
    "Timestamp"server timestamp for the message
    "RequesterWolframID"Wolfram ID of the sender
    "RequesterWolframUUID"Wolfram UUID of the sender
    "ListenerID"ID of the current listener
  • The contents of a message are given literally if the message is a string, Real, Integer, ByteArray, True, False, Null, Image or Image3D, or a list or association of such objects. All other messages are given either in the form HoldComplete[DisableFormatting[expr]] or as a list or association of delayed rules of the form "name"DisableFormatting[val].
  • For security reasons, you should exercise caution in accessing unevaluated message contents, such as parts of held expressions, right-hand sides of delayed rules, or applying ToExpression to string messages.
  • ChannelListen accepts the following options:
  • AutoRemove Falsewhether to remove the listener after receiving one message
    ChannelBase$ChannelBasedefault channel base to assume
    ChannelHistoryLength 100how many messages to store in the listener cache
    NotificationFunction Inheritednotification to give when a message arrives
  • A channel listener set up by ChannelListen can be removed using RemoveChannelListener.
  • Removing a channel listener discards messages cached by the listener.
  • Terminating a Wolfram Language session removes all active channel listeners.

Examples

open allclose all

Basic Examples  (2)Summary of the most common use cases

Create a channel and start listening:

Out[1]=1
Out[2]=2

Send a message to the channel and retrieve the contents of the message from the listener:

Out[3]=3
Out[4]=4

Remove the listener and delete the channel:

Out[5]=5
Out[6]=6

Define a custom handler function that will be executed when a message arrives:

Out[1]=1

Sending a message to the channel causes the function to be called:

The message is also recorded in the ChannelListener object:

Out[3]=3

Remove the listener and delete the channel:

Out[4]=4
Out[5]=5

Scope  (4)Survey of the scope of standard use cases

Channel Specifications  (2)

Listen on a channel defined by a ChannelObject:

Out[1]=1
Out[2]=2

Listen on a channel in your home area on the channel broker server, specifying its name:

Out[3]=3

Listen on a channel specified by its fully qualified name:

Out[4]=4
Out[5]=5

Listen on a channel specified by its full URL:

Out[6]=6
Out[7]=7

Delete the channel, which removes the listener:

Out[8]=8

Listen on a channel in the common area on the server, specified by a URL:

Out[1]=1
Out[2]=2

Delete the channel, which removes the listener:

Out[3]=3

Handlers  (2)

Examine the arguments received by the handler function:

Out[1]=1

Sending a message to the channel prints the association received by the handler:

Delete the channel, which removes the listener:

Out[3]=3

Do not execute any handler function when messages are received:

Out[1]=1
Out[2]=2

You can still retrieve messages sent to the channel:

Out[4]=4

Delete the channel, which removes the listener:

Out[5]=5

Options  (3)Common values & functionality for each option

AutoRemove  (1)

Launch a listener that will remove itself after the first message is received:

Out[1]=1

The listener is active:

Out[2]=2

The listener is automatically removed after a message is sent and processed:

Out[4]=4

Delete the channel:

Out[5]=5

ChannelHistoryLength  (1)

Create a channel listener with ChannelHistoryLength set to 10:

Out[1]=1

Send 20 messages to the channel:

Only the 10 most-recently received messages are stored:

Out[3]=3

Delete the channel, which removes the listener:

NotificationFunction  (1)

Define a custom notification function in the listener:

Out[1]=1

The function is executed once a message is sent and processed:

Delete the channel, which removes the listener:

Applications  (4)Sample problems that can be solved with this function

Email  (1)

In a desktop session, set up a listener that speaks the subject of an incoming message:

Out[1]=1

Create a MailReceiverFunction that forwards received mail to your listener:

Out[2]=2

Send an email to the receiver function and hear your listener speak:

Out[3]=3

Delete the channel, which removes the listener:

Remote Evaluation  (1)

In your Wolfram Cloud account, or any other remote Wolfram System, set up a listener that evaluates incoming messages and sends the result back to a specified channel:

Out[1]=1

Set up a receiving channel on your local system:

Out[2]=2

Send a command to the remote evaluator:

Access the response received:

Out[4]=4

Verify that the result is coming from a different machine:

Out[5]=5

Clean up:

Out[6]=6

Wolfram Cloud  (1)

ChannelListen allows your current session to receive updates from APIFunction, FormFunction and other functions as they are executed in the Wolfram Cloud:

Out[1]=1
Out[2]=2

Deploy a webpage that performs a simple operation and sends the result along with some metadata to the listener:

Out[3]=3

The listener dynamically updates as soon as the web form is submitted:

Delete the channel:

Social Media  (1)

Create an APIFunction that forwards the contents of HTTP requests to a channel:

Out[1]=1

Create an IFTTT applet that tracks mentions of the word "Mathematica" on Twitter and sends them to the APIFunction via HTTP:

Create a listener on the channel:

Out[2]=2

Create a service connection to Twitter and send a tweet containing the keyword:

Out[3]=3
Out[4]=4

List the messages received by the listener:

Out[5]=5

Delete the channel:

Properties & Relations  (3)Properties of the function, and connections to other functions

ChannelListen returns a ChannelListener object:

Out[1]=1

You can query the listener and retrieve its properties:

Out[2]=2

Delete the channel, which removes the listener:

Use RemoveChannelListener to remove a ChannelListener object:

Out[1]=1
Out[2]=2

Delete the channel:

On desktop Wolfram systems, output of Print executed in the message handler function is directed to the Messages window:

Out[1]=1

Delete the channel, which removes the listener:

Possible Issues  (1)Common pitfalls and unexpected behavior

For security reasons, you cannot listen on other users' channels by default:

Out[1]=1
Out[2]=2

If you trust the channel author to potentially execute a message handler function on your computer, you can temporarily override the security setting:

Out[4]=4

Restore the default:

Neat Examples  (1)Surprising or curious use cases

Start listening on a channel and arrange to dynamically plot incoming points as they arrive:

Out[1]=1
Out[2]=2

Send data to the channel from the current session or from any other Wolfram Language session connected to the internet:

Set up a task to send points periodically to a channel's URL:

Out[4]=4

Stop sending data and delete the channel:

Out[5]=5
Wolfram Research (2016), ChannelListen, Wolfram Language function, https://reference.wolfram.com/language/ref/ChannelListen.html (updated 2020).
Wolfram Research (2016), ChannelListen, Wolfram Language function, https://reference.wolfram.com/language/ref/ChannelListen.html (updated 2020).

Text

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

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

CMS

Wolfram Language. 2016. "ChannelListen." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/ChannelListen.html.

Wolfram Language. 2016. "ChannelListen." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/ChannelListen.html.

APA

Wolfram Language. (2016). ChannelListen. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ChannelListen.html

Wolfram Language. (2016). ChannelListen. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ChannelListen.html

BibTeX

@misc{reference.wolfram_2025_channellisten, author="Wolfram Research", title="{ChannelListen}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/ChannelListen.html}", note=[Accessed: 26-April-2025 ]}

@misc{reference.wolfram_2025_channellisten, author="Wolfram Research", title="{ChannelListen}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/ChannelListen.html}", note=[Accessed: 26-April-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_channellisten, organization={Wolfram Research}, title={ChannelListen}, year={2020}, url={https://reference.wolfram.com/language/ref/ChannelListen.html}, note=[Accessed: 26-April-2025 ]}

@online{reference.wolfram_2025_channellisten, organization={Wolfram Research}, title={ChannelListen}, year={2020}, url={https://reference.wolfram.com/language/ref/ChannelListen.html}, note=[Accessed: 26-April-2025 ]}