Sockets
Sockets[]
returns all active socket connections initiated by your current Wolfram Language session.
returns all sockets connected to your current session, including remote sockets originating outside your current session.
Sockets[spec]
returns only sockets specified by spec.
Details
- Returned sockets are all given as SocketObject constructs.
- Possible forms of spec include:
-
"Remote" sockets that originate outside the current session "Local" sockets that originate within the current session "Server" local sockets opened with SocketOpen "Client" local sockets connected with SocketConnect "TCP" sockets with protocol of "TCP" "ZMQ" sockets with protocol of "ZMQ" {"ZMQ","type"} sockets with protocol "ZMQ_type" All all local and remote sockets - Close closes socket connections and frees associated resources.
- If a socket is opened with SocketOpen and connected to in the same Wolfram Language session with SocketConnect, both sides of the socket will have an associated SocketObject.
Examples
open allclose allScope (2)
Only see local sockets on your machine:
Listen on a socket with SocketListen and see the socket that is listened on:
The socket can also be viewed with the property "Socket" on the SocketListener[…] object:
Possible Issues (1)
When connecting to a server socket with SocketConnect in the same session, the socket returned by SocketConnect is different than the socket object returned by the server socket's "ConnectedClients" property.
Open a server socket and connect a client to it:
Sockets[] will only show the connections you opened, because they are both local:
There is also an additional remote socket created with the same details as the client socket accessible inside Sockets["Remote"]:
The UUID for the remote client does not match the local client returned by SocketConnect:
These two sockets are the two ends of the socket connection; writing to one of them will send a message to the other:
Closing the server will disconnect the remote client and remove it from the list of active sockets:
Text
Wolfram Research (2017), Sockets, Wolfram Language function, https://reference.wolfram.com/language/ref/Sockets.html (updated 2020).
CMS
Wolfram Language. 2017. "Sockets." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/Sockets.html.
APA
Wolfram Language. (2017). Sockets. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Sockets.html