OxL Reference

method TcpStream.readText

Like read, for UTF-8 text; bytes that are not valid UTF-8 give ProtocolError.

Example:

oxl✓ checked in CI
use std.net { SocketAddr, TcpListener, TcpStream, IpAddr }

fn main() -> () | NetError | ParseError  io, net {
  let l = TcpListener.bind(SocketAddr.parse("127.0.0.1:0")?)?
  defer l.close()?
  let c = TcpStream.connect(l.local, 2s)?
  defer c.close()?
  let s = l.accept(3s)?
  defer s.close()?
  c.writeText("héllo")?
  print(s.readText(64)?)
}
Output
héllo
pub(api) fn readText(max: usize, timeout: Duration? = none) -> str | NetError  net

Since. 1.0.0-beta

Parameters

NameType
maxusize
timeoutDuration? = none

Returns

str

Errors

  • NetError
  • those of `read`; `ProtocolError` when the bytes are not valid UTF-8.

Effects

net

Defined in: std/net/net.oxl:580

See also