tcp_output_stream(?Socket, -Stream)

Returns the output stream Stream from the socket file descriptor term Socket. You can write to the stream using the regular stream output predicates.

Output on socket streams are buffered. If you want to send characters one at a time, you must follow each write with a flush, as in

     tcp_output_stream(Socket, Stream),
     put(Stream, Character),

If you try to write to a broken socket, the "Broken pipe" exception is raised: