
TCPStream

.sub main :main
load_bytecode 'library/tcpstream.pir'
.local pmc stream
stream = new 'TCPStream'
stream.'connect'("www.google.com", 80)
stream.'say'("GET / HTTP/1.0")
stream.'say'("User-agent: Parrot")
stream.'say'("")
$S0 = stream.'slurp'()
print $S0
stream.'close'()
.end

This is a high-level sockets library designed to mimic Tcl's socket builtins. As such, it uses print and say instead of send and readline and slurp instead of recv.

initInitialize a TCPStream object (create a socket and a buffer).
init_pmcInitialize a TCPStream object from an already pre-existing socket. This can be use to create servers, among other things.
get_boolReturns whether or not this socket has data waiting to be read.

void close()Closes the socket.
void connect(string host, int port)Connects to a host/port.
Throws an exception if unable to connect.
void flush()
string readline()Reads and returns up to (and excluding) an end-of-line character and discards the end-of-line character.
void say(string msg)Print msg and an end-of-line character to the socket.
string slurp()Return all the data in the socket.

Matt Diephouse <matt@diephouse.com>.