de.mud.telnet

Class TelnetProtocolHandler


public abstract class TelnetProtocolHandler
extends java.lang.Object

This is a telnet protocol handler. The handler needs implementations for several methods to handle the telnet options and to be able to read and write the buffer.

Maintainer: Marcus Meissner

Version:
$Id: TelnetProtocolHandler.java 503 2005-10-24 07:34:13Z marcus $
Author:
Matthias L. Jugel, Marcus Meissner

Field Summary

static String
ID
contains the current revision id

Constructor Summary

TelnetProtocolHandler()
Create a new telnet protocol handler.

Method Summary

protected abstract String
getTerminalType()
Get the current terminal type for TTYPE telnet option.
protected abstract Dimension
getWindowSize()
Get the current window size of the terminal for the NAWS telnet option.
void
inputfeed(byte[] b, int len)
int
negotiate(nbuf[] )
Handle telnet protocol negotiation.
protected abstract void
notifyEndOfRecord()
Generate an EOR (end of record) request.
void
reset()
Reset the protocol handler.
void
sendTelnetControl(byte code)
Send a Telnet Escape character (IAC )
void
setCR(String xcr)
void
setCRLF(String xcrlf)
protected abstract void
setLocalEcho(boolean echo)
Set the local echo option of telnet.
void
setWindowSize(int columns, int rows)
Send the new Window Size (via NAWS)
void
startup()
Do not send any notifications at startup.
void
transpose(byte[] buf)
Transpose special telnet codes like 0xff or newlines to values that are compliant to the protocol.
protected abstract void
write(byte[] b)
Send data to the remote host.

Field Details

ID

public static final String ID
contains the current revision id

Constructor Details

TelnetProtocolHandler

public TelnetProtocolHandler()
Create a new telnet protocol handler.

Method Details

getTerminalType

protected abstract String getTerminalType()
Get the current terminal type for TTYPE telnet option.
Returns:
the string id of the terminal

getWindowSize

protected abstract Dimension getWindowSize()
Get the current window size of the terminal for the NAWS telnet option.
Returns:
the size of the terminal as Dimension

inputfeed

public void inputfeed(byte[] b,
                      int len)

negotiate

public int negotiate(nbuf[] )
            throws IOException
Parameters:
Returns:
number of bytes processed, 0 for none, and -1 for end of buffer.

notifyEndOfRecord

protected abstract void notifyEndOfRecord()
Generate an EOR (end of record) request. For use by prompt displaying.

reset

public void reset()
Reset the protocol handler. This may be necessary after the connection was closed or some other problem occured.

sendTelnetControl

public void sendTelnetControl(byte code)
            throws IOException
Send a Telnet Escape character (IAC )

setCR

public void setCR(String xcr)

setCRLF

public void setCRLF(String xcrlf)

setLocalEcho

protected abstract void setLocalEcho(boolean echo)
Set the local echo option of telnet.
Parameters:
echo - true for local echo, false for no local echo

setWindowSize

public void setWindowSize(int columns,
                          int rows)
            throws IOException
Send the new Window Size (via NAWS)

startup

public void startup()
            throws IOException
Do not send any notifications at startup. We do not know, whether the remote client understands telnet protocol handling, so we are silent. (This used to send IAC WILL SGA, but this is false for a compliant client.)

transpose

public void transpose(byte[] buf)
            throws IOException
Transpose special telnet codes like 0xff or newlines to values that are compliant to the protocol. This method will also send the buffer immediately after transposing the data.
Parameters:
buf - the data buffer to be sent

write

protected abstract void write(byte[] b)
            throws IOException
Send data to the remote host.
Parameters:
b - array of bytes to send