This is a library for communicating with NNTP (network news transport protocol). It also aims to support more protocols. This library is very much work in progress.
This library offers a framework for writing general request/response types of protocols.
Protocol.protocolThis class offers support for general protocol support. It has the following public methods.
init init(host:+HostV
port:+PortI
reopen:+ReopenB<= false
Creates a new connection to host +HostV at port +PortI. If +ReopenB is true, the connection will be reopened if it's lost.
query query(+QueriesRs)
Processes a list of queries.
request request(+QueryR)
Processes a single query. Both of these methods take records with arguments passed in bound fields and replies passed in unbound ones. All replies have the field status in common with them. Common replies for this are atoms ok, for success, and closed, for a closed connection. A closed connection cannot be reopened; create a new connection if you want it.
close close
Closes the connection.
bytesRead bytesRead(AmountIs)
Returns the amount of bytes read by this connection so far. This is a list, with the tail bound when more bytes are read.
bytesWritten bytesWritten(AmountIs)
Returns the amount of bytes written so far. Similar to bytesRead.
Protocol.protocol has also the following features.
hostHost address this protocol object is connected to.
portHost port.
Protocol.protocol can be subclassed. It has some additional methods for this use and requires a few methods.
sendTextsendText(vs:+V
request:+R<= nil)
Send the text message +V to the host. If +R is not nil, it is passed to the client's port.
parserMsgparserMsg(+R)
Send message +R to the client from the parser.
parserMsgparserMsg(+R)
Send message +R to the parser from the client.
parseparse(+S)
This method has to be defined when implementing new protocols. +S is a list of characters received from the host. The parser typically communicates with the client with parserMsg. When the stream is closed, the parser has to call parserMsg(closed). This method will call itself recursively until the connection is closed.
Also, the method request has to be defined by the subclass.