The Channel Framework

or

How to Talk to Your Wolfram Language Session

Igor Bakshee
Wolfram Research

Go ahead and join the fun:

ChannelListen["Demos:Oneliner"];

Join the Conversation #WolframTechConf

Overview

Bird’s-eye view of the framework

The publish-subscribe model

When you need channels and when you don’t

Fun examples (applications)

What is it?

A framework for communicating between WL and ANY device capable of making an HTTP request.

Start a listener… sets up a message processing function:

listener = ChannelListen["speak", Speak["Arrived " <> ToString[Lookup[#Message, "param"]]] &, Permissions -> "Public"]

Dynamic[listener["Message"]]

Send a message to the listener from a terminal (from anywhere in the world):

"curl \""<>URLBuild[listener["URL"],{"operation"->"send","param"->123}]<>"\""

Send a message from a browser:

URLBuild[listener["URL"],{"operation"->"send","param"->456}]

Send a message from a Wolfram Language session:

ChannelSend[$WolframID<>":speak",<|"param"->789|>]

All data received by the listener:

listener["Dataset"]

RemoveChannelListener[listener]

Behind the scenes

Server-brokered communication:

$ChannelBase

The Publish-Subscribe model

Abstract away details of communication between particular devices.

Send data to a generic channel (not a specific subscriber)

Receive data from a channel (not a specific publisher)

Scalable: One-to-one, one-to-many, many-to-one and many-to-many channels

You do not need the framework when…

You are more interested in the result of evaluation rather than where it occurs (use APIFunction, FormFunction, …)

You want to store data permanently somewhere (use CloudObject, Wolfram Data Drop, …)

When do you need it?

To pass data to your current WL session

Execute messages asynchronously in your current session

Execute messages on a specific machine (or a number of subscriber machines)

Application: Dashboards for remote data

Start listening:

listener=ChannelListen["points"]

Dynamic[ListLinePlot[If[AssociationQ[#],Lookup[#,"points"],{}]&@listener["Message"],PlotTheme->"Marketing"]]

Application: Remote evaluation

Start a listener:

listener=ChannelListen["local"]

Dynamic[listener["Message"]]

Send a command to the remote evaluator and notice the result in the dynamic output.

ChannelSend["remote",<|"Evaluate":>{$OperatingSystem,$MachineID},"ReplyTo"->"local"|>]

Not my machine:

{$OperatingSystem,$MachineID}

Can be used for SETI@home-like projects… talk to us.

More applications

Send data from Arduino Yun

Go to Ian Johnson’s talk.

Set Up Your Own Programmable Chat and Instant Messaging

A demo chat client that you can modify and play is available with the Wolfram Language:

As well as a WIM client (see ref/ChannelListen):

A much more sophisticated chat system: see Andre Kuzniarek… and the Coding Competition event tonight.

Integrate with Social Media

Integrate with virtually no programming, for instance, using IFTTT.

See a running demo in the Connectivity booth downstairs…

Evaluate Email Messages in Your Session—or Be Notified When Your APIFunction Is Executed in the Cloud

Just include ChannelSend[…] in your API function.

MailReceiverFunction[With[{user=$WolframID},
ChannelSend[user<>":"<>"mailSpeak",<|"msg"->#Subject,"from"->#From|>]&]]//CloudDeploy

Extend Amazon Lambda, Google Cloud Functions and Other Serverless Apps

Set Up Push Notifications

Roll Out Your Own Multi-user Games

Talk to Jaw Warendorff about playing chess in Mathematica.

Summary

Applications are many...

If a system can make an HTTP request, it can also communicate with your Wolfram Language session!

More Info

Examples

Function overview in the documentation or on the web

More demos

... In the Connectivity booth (break area downstairs)

Questions?

See me Friday morning 10...12 AM (in the Connectivity booth).