Telnet

paket "telnet";

The telnet package allows you to create a telnet client.

TelnetClient constructor

Use the TelnetClient constructor to instantiate a TelnetKlijent object, that you will use for all telnet communication.

ƒ TelnetKlijent() : objekat
var klijent = TelnetKlijent();

TelnetKlijent

The TelnetKlijent object has the following properties:

  1. uspostaviKonekciju
  2. zatvoriKonekciju
  3. izlazniTok
  4. ulazniTok

uspostaviKonekciju

The uspostaviKonekciju function is used to establish a connection with a Telnet server.

ƒ uspostaviKonekciju(hostname: tekst, port: broj) : void (nedefinisano)
var klijent = TelnetKlijent();

probaj {
    klijent.uspostaviKonekciju("localhost", 23);
}
spasi {
    ispis("Could not connect!");
}

zatvoriKonekciju

The zatvoriKonekciju function is used to end an established connection with a Telnet server.

ƒ zatvoriKonekciju() : void (nedefinisano)
klijent.zatvoriKonekciju();

izlazniTok

The izlazniTok function returns the output stream of a Telnet client.

ƒ izlazniTok() : objekat
var izlaz = klijent.izlazniTok();

ulazniTok

The ulazniTok function returns the input stream of a Telnet client.

ƒ ulazniTok() : objekat
var ulaz = klijent.ulazniTok();

Output Stream object

The output stream object, in simple terms, collects output bytes and sends them to some sink. In the context of Telnet, you will use it for sending messages towards the server.

posaljiBajt

The posaljiBajt function sends a single byte down the output stream.

ƒ posaljiBajt(b: broj) : void (nedefinisano)
izlaz.posaljiBajt(5);

posalji

The posalji function sends a byte array down the output stream.

ƒ posalji(bytes: BajtNiz) : void (nedefinisano)
izlaz.posalji("Hello World".bajti());

isprazni

The isprazni function flushes the output stream.

ƒ isprazni() : void (nedefinisano)
izlaz.posalji("Hello".bajti());
izlaz.posalji("World".bajti());

izlaz.isprazni();

Note that you will need to flush the output stream to actually send its contents.

zatvori

The zatvori function closes the output stream.

ƒ zatvori() : void (nedefinisano)
izlaz.zatvori();

pisac

The pisac function returns the buffered writer object for this output stream.

ƒ pisac() : objekat
var writer = izlaz.pisac();

Input Stream Object

An Input Stream object is the opposite of an Output Stream object. It collects incoming bytes. In the context of Telnet, you will use it to read messages you get from the server.

zatvoriTok

The zatvoriTok function closes the input stream.

ƒ zatvoriTok() : void (nedefinisano)
izlaz.zatvoriTok();

ucitaj

The ucitaj function reads a given number of bytes from the input stream.

ƒ ucitaj(n: broj) : BajtNiz
// Reads 1024 bytes
var odgovor = ulaz.ucitaj(1024);
ispis(odgovor.dekodiraj());

ucitajPreostaleBajte

The ucitajPreostaleBajte function reads all remaining bytes from the input stream.

ƒ ucitajPreostaleBajte() : BajtNiz
var odgovor = ulaz.ucitajPreostaleBajte(1024);
ispis(odgovor.dekodiraj());

dostupnihBajtova

The dostupnihBajtova function returns an estimated number of bytes that can be read (or skipped over) from this input stream without blocking.

ƒ dostupnihBajtova() : broj
var available = ulaz.dostupnihBajtova();

preskoci

The preskoci function skips over and discards a specified number of bytes of data from the input stream. It returns the number of bytes actually skiped, since sometimes the number can be lower than the one specified in the arguments.

ƒ preskoci(n: broj) : broj
var actuallySkipped = ulaz.preskoci(8);

citac

The citac function returns the buffered reader object for this input stream.

ƒ citac() : objekat
var reader = klijent.ulazniTok.citac();