Sockets
✖
Sockets
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 allBasic Examples (1)Summary of the most common use cases
Scope (2)Survey of the scope of standard use cases
Only see local sockets on your machine:

https://wolfram.com/xid/0b8b7m498v-5c5nf2


https://wolfram.com/xid/0b8b7m498v-qvl0t

Listen on a socket with SocketListen and see the socket that is listened on:

https://wolfram.com/xid/0b8b7m498v-88uyor


https://wolfram.com/xid/0b8b7m498v-i08ssz

The socket can also be viewed with the property "Socket" on the SocketListener[…] object:

https://wolfram.com/xid/0b8b7m498v-8zwa7

Close the socket and delete the listener:

https://wolfram.com/xid/0b8b7m498v-de1a1o


https://wolfram.com/xid/0b8b7m498v-fptktw
Possible Issues (1)Common pitfalls and unexpected behavior
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:

https://wolfram.com/xid/0b8b7m498v-zzn6ez
Sockets[] will only show the connections you opened, because they are both local:

https://wolfram.com/xid/0b8b7m498v-7dmti2


There is also an additional remote socket created with the same details as the client socket accessible inside Sockets["Remote"]:

https://wolfram.com/xid/0b8b7m498v-3o64hr

The UUID for the remote client does not match the local client returned by SocketConnect:

https://wolfram.com/xid/0b8b7m498v-ztammi

These two sockets are the two ends of the socket connection; writing to one of them will send a message to the other:

https://wolfram.com/xid/0b8b7m498v-webnh


https://wolfram.com/xid/0b8b7m498v-sj6za8

Closing the server will disconnect the remote client and remove it from the list of active sockets:

https://wolfram.com/xid/0b8b7m498v-38qjqj


https://wolfram.com/xid/0b8b7m498v-fkkrxp

Wolfram Research (2017), Sockets, Wolfram Language function, https://reference.wolfram.com/language/ref/Sockets.html (updated 2020).
Text
Wolfram Research (2017), Sockets, Wolfram Language function, https://reference.wolfram.com/language/ref/Sockets.html (updated 2020).
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.
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
Wolfram Language. (2017). Sockets. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Sockets.html
BibTeX
@misc{reference.wolfram_2025_sockets, author="Wolfram Research", title="{Sockets}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/Sockets.html}", note=[Accessed: 21-February-2025
]}
BibLaTeX
@online{reference.wolfram_2025_sockets, organization={Wolfram Research}, title={Sockets}, year={2020}, url={https://reference.wolfram.com/language/ref/Sockets.html}, note=[Accessed: 21-February-2025
]}