SocketObject

SocketObject[]

represents a network socket connection.

Details

  • Both SocketConnect and SocketOpen give SocketObject[].
  • Functions that operate on socket connections specified by SocketObject include Read, Write, ReadString, WriteString, BinaryRead and BinaryWrite.
  • Socket connections are closed using Close.
  • SocketConnect creates a socket connection from a source address to a destination address.
  • SocketOpen opens a socket at a destination address that accepts connections from source addresses.
  • Properties of a socket connection can be found using SocketObject[][prop] or Options[SocketObject[],prop]. When applicable, options can be set using SetOptions.
  • Properties for all connections include:
  • "SourceIPAddress"the complete source IP address including port as a string
    "SourcePort"the source port number (as an integer)
    "DestinationIPAddress"the complete destination IP address including port as a string
    "DestinationPort"the destination port number (as an integer)
    "Protocol"the connection protocol used ("TCP", "ZMQ", ...)
    "UUID"the asociated UUID for the socket

Examples

Basic Examples  (3)

Open a connection to a server specified by a URL:

In[1]:=
Click for copyable input
Out[1]=

Write to the socket:

In[2]:=
Click for copyable input

Read the result as a string:

In[3]:=
Click for copyable input
Out[3]=

Close the socket connection:

In[4]:=
Click for copyable input
Out[4]=

Connect to a server:

In[1]:=
Click for copyable input
Out[1]=

Get the outgoing "SourceIPAddress" on your machine for this socket:

In[2]:=
Click for copyable input
Out[2]=

Close the socket:

In[3]:=
Click for copyable input
Out[3]=

Open a "ZMQ" socket to listen on and connect a client to it:

In[1]:=
Click for copyable input
Out[1]=

The default "Protocol" for "ZMQ" sockets is "ZMQ_Pair":

In[2]:=
Click for copyable input
Out[2]=

Close the socket:

In[3]:=
Click for copyable input
Out[3]=

See Also

Sockets  SocketConnect  InputStream  OutputStream  CloudObject  DeviceObject

Introduced in 2015
(10.3)
| Updated in 2017
(11.2)