Interprocess Communication (IPC) · Opening Connections (hopen) · Practice Question
Specify a Timeout When Opening a Connection
Question
How can you specify a timeout when opening a connection, and what effect does the timeout parameter have?
Solution
h:hopen (`::5001;10000)Explanation
hopen accepts a 2-item list: the connection descriptor, and a timeout in milliseconds. hopen (`::5001;10000) allows up to 10 seconds for the handshake to complete, raising 'timeout if it doesn't.
The timeout covers only the connection attempt — once open, ordinary calls over that handle can still block indefinitely. If nothing is listening at all, hopen typically fails immediately rather than waiting out the timeout; the timeout matters when the target exists but is slow to respond.