starts listening on the specified socket, asynchronously applying fun whenever data is received on the socket.


starts listening for active connections on the specified port of


starts listening for active connections on the specified address address on the local machine.


starts listening for active connections defined by spec using the options opts.


starts listening for active connections defined by spec, but does not set up handler functions, etc.

Details and Options

  • In SocketListen[socket,], socket is of the form SocketObject[].
  • SocketListen[] gives a SocketListener object.
  • For ZMQ sockets, fun is by default applied whether or not a complete message is received.
  • For raw TCP sockets, fun is by default applied to every data buffer generated by the operating system.
  • With the option settings RecordSeparators->"s" or RecordSeparators->{"s1","s2",}, fun is applied to each block of data received between successive delimiters matching s or the si.
  • The function fun is applied to an association representing each event, with the following default keys:
  • "Data"the data received, as a string
    "Socket"the SocketObject being listened on
    "SourceSocket"the SocketObject that generated the event
    "Timestamp"time when the event occurred (as a DateObject)
  • The following additional keys can also be requested in HandlerFunctionsKeys:
  • "DataBytes"the raw data received, as a list of byte values
    "DataByteArray"the raw data received, as a ByteArray object
    "MultipartComplete"whether a multipart ZMQ message is complete
  • SocketListen accepts the following options:
  • CharacterEncoding$CharacterEncodingthe character encoding to assume
    HandlerFunctionsKeysDefaultkeys to include in the data association
    HandlerFunctionsAutomatichow to handle socket events
    RecordSeparatorsNonehow messages are taken to be delimited
  • The following events can be generated while listening on the socket:
  • "DataReceived"data is available on the socket


open all close all

Basic Examples  (1)

Listen on an available socket to print off the association for the event:

Click for copyable input

Send some data (printed messages may appear in the Messages window):

Click for copyable input

Delete the listener and close the sockets:

Click for copyable input

Scope  (2)

Options  (5)

Applications  (1)

Interactive Examples  (1)

Introduced in 2017