NAME
Punk::Test::WS::Conn - the client side of one WebSocket connection
SYNOPSIS
my $conn = Punk::Test::WS::Conn->new(sock => $s, timeout => 5);
my $hdr = $conn->read_headers; # the raw HTTP header block
$conn->send_frame(opcode => 1, payload => 'hi');
my $f = $conn->read_frame; # one decoded frame
$conn->close;
DESCRIPTION
A connected socket wrapped with a read buffer and a timeout, speaking the Punk::Test::WS codec from the client's side. Punk::Test builds one over either of its transports - an in-process socketpair or a live TCP connection - and the assertion methods drive it. Every read carries the timeout, so a server that goes quiet fails the test instead of hanging it.
METHODS
new(%args)
sock (the connected socket), timeout (seconds per read, default 5), pid (a child process to reap when the connection closes, for transports that forked one).
sock
The underlying socket.
read_headers
Read until a full HTTP header block (\r\n\r\n) has arrived; returns it raw - empty on EOF or timeout.
send_frame(%args)
Encode one client frame (masked, as a client must - the arguments are "encode_client" in Punk::Test::WS's) and write it. Returns what syswrite returned.
read_frame
One decoded frame off the wire, buffering as needed; undef on timeout or EOF. A protocol violation in the stream dies with the codec's error name.
close
Close the socket and reap the child, if this connection owns one. Called on destruction.
SEE ALSO
AUTHOR
LNATION <email@lnation.org>
LICENSE AND COPYRIGHT
This software is Copyright (c) 2026 by LNATION <email@lnation.org>.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)