Skip to content
Snippets Groups Projects
Commit c301721a authored by rswindell's avatar rswindell
Browse files

A library for finger or systat/active-user client requests

(mostly migrated from exec/finger.js).
parent f056efcc
Branches
Tags
No related merge requests found
// $Id$
// A Finger/SYSTAT client library
"use strict";
require('sockdefs.js', 'SOCK_DGRAM');
require('portdefs.js', 'standard_service_port');
// Returns a String on failure, an Array of lines on success
function request(host, query, protocol, udp)
{
if (protocol === undefined)
protocol = "finger";
var sock = new Socket(udp === true ? SOCK_DGRAM : SOCK_STREAM);
if(!sock.connect(host, standard_service_port[protocol]))
return "Connection to " + host + " failed with error " + sock.last_error;
if(query !== undefined)
sock.send(query + "\r\n");
var output = [];
if(udp) {
output.push(sock.recvfrom().data);
}
else {
while(sock.is_connected && !js.terminated) {
var line = sock.readline();
if(line != null)
output.push(line);
}
}
sock.close();
return output;
}
this;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment