tcp_client_stream(address, @key port_number, keep_alive, coalesce = true, transcoder)
Return a tcp-client-stream that represent a connection to a TCP server and allows communication with that server.
Address
indicates the internet address of the server, and possibly the IP port number.
A string of the form "INTF:PORT" will be parsed and the value of INTF
will be assigned
to address and the integer value of PORT
will be assigned to port_number.
This argument can also be a 4 element u8array which contains the 32-bit IPv4 address or
an 8 element u8array which contains the 128-bit IPv6 address.
Port_number
must be an exact integer. Indicates the IP port number of the server to connect.
Keep_alive
should be either true or false.
Controls the use of the keep alive
option on the connection. The "keep alive" option will periodically send control packets on
otherwise idle network connections to ensure that the server host is active and reachable.
The default value of this setting is false.
Coalesce
should be either true or false.
Controls the use of Nagle's algorithm
which reduces the number of small packets by delaying their transmission and coalescing
them into larger packets. A setting of true will coalesce small packets into larger ones.
A setting of false will transmit packets as soon as possible.
The default value of this setting is true. Note that this setting does not
affect the buffering of the stream.
Transcoder
, if present, must be a transcoder object that will be used to encode and decode
characters in the stream.
// A simple network echo server:
let s = tcp_server_stream(2020)
function echo(client)
{ showln(stream = client, read_line(client))
flush_writer(client) }
letfn loop (client = read(s))
{ !call_with_stream(client, echo)
loop(read(s)) }
// The following code can be used to test the echo server:
let c = tcp_client_stream("localhost:2020")
showln(stream = c, "hello")
flush_writer(c)
read_line(c)
//> hello