thor.net
Class TelnetURLConnection

java.lang.Object
  |
  +--java.net.URLConnection
        |
        +--thor.net.TelnetURLConnection
All Implemented Interfaces:
TelnetConstants

public class TelnetURLConnection
extends java.net.URLConnection
implements TelnetConstants

This is class creates a Telnet connection from a telnet URL, see the thor.app classes for examples. The LGPL applies to this software. Unless otherwise stated the software is Copyright 1996,2000 Daniel Kristjansson


Field Summary
 
Fields inherited from class java.net.URLConnection
allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, url, useCaches
 
Fields inherited from interface thor.net.TelnetConstants
AO, AYT, BEL, BRK, BS, CR, DM, DO, DONT, EC, EL, END_OF_RECORD, FF, GA, HT, IAC, IP, LF, NOP, NULL, OUTMRK, SB, SE, TERMINAL_TYPE, TUID, VT, WILL, WONT
 
Constructor Summary
TelnetURLConnection(java.net.URL poURL)
          Creates a TelnetURLConnection object, call connect before using.
 
Method Summary
 void connect()
          This actually connects to the host at the specified port.
 boolean connected()
          If true telnet session is currently open.
 void disconnect()
          Disconnect from the host.
 java.io.InputStream getInputStream()
          Fetches the InputStream from the host.
 java.io.OutputStream getOutputStream()
          Fetches the OutputStream to the host.
 TelnetTerminalHandler getTelnetTerminalHandler()
          Returns the TelnetTerminalHandler currently in use.
 void sendCommand(int command, int option)
          Bypasses the escapes of IAC in the OutputStream and sends a command of the form [IAC,command,option] Use with caution.
 void setTelnetTerminalHandler(TelnetTerminalHandler poHandler)
          This allows you to set your own TelnetTerminalHandler.
 void updateOptions()
          Call this to get options negotiated
 
Methods inherited from class java.net.URLConnection
addRequestProperty, getAllowUserInteraction, getContent, getContent, getContentEncoding, getContentLength, getContentType, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches, getDoInput, getDoOutput, getExpiration, getFileNameMap, getHeaderField, getHeaderField, getHeaderFieldDate, getHeaderFieldInt, getHeaderFieldKey, getHeaderFields, getIfModifiedSince, getLastModified, getPermission, getRequestProperties, getRequestProperty, getURL, getUseCaches, guessContentTypeFromName, guessContentTypeFromStream, setAllowUserInteraction, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDefaultUseCaches, setDoInput, setDoOutput, setFileNameMap, setIfModifiedSince, setRequestProperty, setUseCaches, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TelnetURLConnection

public TelnetURLConnection(java.net.URL poURL)
Creates a TelnetURLConnection object, call connect before using.

Method Detail

connect

public void connect()
             throws java.io.IOException
This actually connects to the host at the specified port. The Input and Output streams are created in this step.

Specified by:
connect in class java.net.URLConnection
java.io.IOException

disconnect

public void disconnect()
                throws java.io.IOException
Disconnect from the host. It would be safe to call connect again.

java.io.IOException

connected

public boolean connected()
If true telnet session is currently open. Unlike a regular URLConnection, it can be closed once open with the disconnect method.


getOutputStream

public java.io.OutputStream getOutputStream()
Fetches the OutputStream to the host. IAC (ascii 255) is escaped, all other characters pass through unaffected.

Overrides:
getOutputStream in class java.net.URLConnection

getInputStream

public java.io.InputStream getInputStream()
Fetches the InputStream from the host. All telnet special characters are stripped from the data stream and either handled directly or forwarded to the TelnetTerminalHandler. Generally options are requested in by the TelnetTerminalHandler, and it handles special characters LF, CR, BELL, BACKSPACE, etc itself. These are optional in the standard but are really important for a decent terminal program.

The DefaultTelnetTerminalHandler handles options gracefully, but doesn't handle the LF, CR, etc at all. See the examples in thor.app for examples on how to handle these.

Overrides:
getInputStream in class java.net.URLConnection

setTelnetTerminalHandler

public void setTelnetTerminalHandler(TelnetTerminalHandler poHandler)
This allows you to set your own TelnetTerminalHandler. Implementing a TelnetTerminalHandler is generally the first step in writing a telnet program.


getTelnetTerminalHandler

public TelnetTerminalHandler getTelnetTerminalHandler()
Returns the TelnetTerminalHandler currently in use.


sendCommand

public void sendCommand(int command,
                        int option)
                 throws java.io.IOException
Bypasses the escapes of IAC in the OutputStream and sends a command of the form [IAC,command,option] Use with caution.

java.io.IOException

updateOptions

public void updateOptions()
Call this to get options negotiated