SocketWaitNext[{socket1,socket2,…}]
waits until there is data ready to read on any of the socketi, then returns that socket.
SocketWaitNext
SocketWaitNext[{socket1,socket2,…}]
waits until there is data ready to read on any of the socketi, then returns that socket.
Details
- The socketi are specified as SocketObject[…].
- SocketWaitNext does not support web sockets.
Examples
open all close allBasic Examples (2)
Connect to a site 5 times and measure how long it takes for the first connection to be ready:
socks = Table[SocketConnect["http://exampledata.wolfram.com"], 5];Write a request out on all the sockets and measure how long it takes for at least one of them to get back a request:
WriteString[#, "GET /50states.txt HTTP/1.1
"]& /@ socks;
First@AbsoluteTiming[SocketWaitNext[socks]]Close /@ socks;Open a server socket and connect some clients to it:
server = SocketOpen[Automatic];
clients = Table[SocketConnect[server], 4];Initially, none of the clients are ready:
SocketReadyQ /@ clientsWrite data to a random client from the server in the local session after a delay of 3 seconds:
SessionSubmit[ScheduledTask[WriteString[RandomChoice[server["ConnectedClients"]], DateString[]], {3}]]Read the data sent to the client once it has been submitted:
ByteArrayToString[SocketReadMessage[First[SocketWaitNext[clients]]]]Close[server];
Close /@ clients;Possible Issues (1)
SocketWaitNext does not support web sockets:
socket = SocketConnect["wss://echo.websocket.org"];
SocketWaitNext[{socket}]See Also
Related Guides
History
Text
Wolfram Research (2017), SocketWaitNext, Wolfram Language function, https://reference.wolfram.com/language/ref/SocketWaitNext.html.
CMS
Wolfram Language. 2017. "SocketWaitNext." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/SocketWaitNext.html.
APA
Wolfram Language. (2017). SocketWaitNext. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SocketWaitNext.html
BibTeX
@misc{reference.wolfram_2026_socketwaitnext, author="Wolfram Research", title="{SocketWaitNext}", year="2017", howpublished="\url{https://reference.wolfram.com/language/ref/SocketWaitNext.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_socketwaitnext, organization={Wolfram Research}, title={SocketWaitNext}, year={2017}, url={https://reference.wolfram.com/language/ref/SocketWaitNext.html}, note=[Accessed: 13-June-2026]}