SocketOpen

SocketOpen[port]

opens a socket that accepts TCP connections to localhost:port and returns a SocketObject representing the socket.

SocketOpen[address]

opens a socket that accepts TCP connections to the specified local address.

SocketOpen[address,"protocol"]

opens a socket that accepts connections with the specified protocol.

Details

  • Supported protocols include:
  • "TCP"raw TCP stream protocol
    "ZMQ"ZeroMQ one-to-one message protocol
    "ZMQ_type"ZeroMQ protocol of the specified type
  • For ZMQ sockets, all possible non-draft types are supported.
  • With no ZMQ protocol type specified, the underlying socket is a "ZMQ_PAIR" socket.
  • SocketOpen opens sockets only on your local machine.
  • SocketOpen can use local addresses only. Possible forms include:
  • {host,port}local hostname or IP address and port number
    {host,"service"}local hostname or IP address and service name
    "host:port"local hostname or IP address with port
    {host,Automatic}an available port on the specified host
    Automatican available port on localhost
  • Hostnames have forms like "www.wolfram.com".
  • IP addresses can be given as "140.177.0.0" or IPAddress[string], where string is an IPv4 or IPv6 IP address.
  • SocketConnect can be used to connect to sockets opened by SocketOpen. The fact that a socket is open on one machine does not guarantee that another machine can connect to it.
  • For a connection to be established, the protocol must be consistent, and there must be no firewalls etc. blocking it.
  • Close can be used to close a connection opened by SocketOpen.

Examples

open allclose all

Basic Examples  (2)

Open a socket to allow client connections to it:

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

Connect a client to it:

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

Close the sockets:

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

Open a ZMQ socket:

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

Connect a client to the server:

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

Write a message from the client to the server:

In[3]:=
Click for copyable input

Read the message on the server:

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

Close the sockets:

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

Scope  (2)

Applications  (1)

Possible Issues  (1)

See Also

SocketConnect  SocketObject  SocketListen  CloudDeploy

Introduced in 2017
(11.2)