Telnet Provider

 

Telnet is a standard terminal emulation protocol used for remote terminal connections. The Telnet protocol enables you to log into a remote system from a terminal and to use the system's resources as though it were directly connected to the terminal.

 

The com.adventnet.cli.transport package contains the implementation of CLITransportProvider and CLIProtocolOptions for Serial communication.

 

TelnetTransportImpl

 

The TelnetTransportImplclass is for sending commands through Telnet. The various Telnet commands include opening and closing of the Telnet connection to the remote device, sending and receiving messages from the opened connection.

 

TelnetProtocolOptionsImpl

 

The TelnetProtocolOptionsImpl class provides the Telnet implementation of the CLIProtocolOptions interface. It contains parameters such as the Remote Host Address, Port, login parameters, and others. In order to establish a CLI session over Telnet with a particular device, the appropriate parameters have to be set on an instance of this class and passed to the CLISession's constructor. Subsequent call to the open method in CLISession will establishes the Telnet connection based on the parameters set here.

 

TelnetProtocolOptionsImpl tpoi = new TelnetProtocolOptionsImpl();

tpoi.setRemoteHost("localhost");

tpoi.setRemotePort(23);

tpoi.setPrompt("$");

tpoi.setLoginName("guest");

tpoi.setPassword("guest");

CLISession clisession = new CLISession(tpoi);

clisession.setTransportProviderClassName

(com.adventnet.cli.transport.TelnetTransportImpl);

clisession.open();

 

TelnetSession

 

You can use TelnetSession class to establish Telnet connections with the desired device. Telnet connections take place after you log in to the device with an appropriate login name and password.

 

TelnetSession API provides the following methods to set the connection parameters:

 

Method Purpose

connect(java.lang.String remoteHost, int remotePort)

This method can be used to connect a remote device where the remote port can also be set.

setLoginPrompt(java.lang.String loginPrompt)

This method can be used to set the login prompt.

setPasswdPrompt(java.lang.String passwordPrompt)

This method can be used to set the password prompt.

setPrompt(java.lang.String prompt)

This method can be used to set the prompt to receive response.

setSocketTimeout(int timeout)

This method can be used to set the socket time-out so the socket can be closed when connection is not established within time-out.

login(java.lang.String login, java.lang.String password)

This method can be used to login into a device with specifying the login name and password.

 

The following code snippet explains how to establish a Telnet session with a remote device.

 

TelnetSession session = new TelnetSession();

session.connect( localhost, 23 );

session.setPrompt("$");

session.setLoginPrompt("login:");

session.setPasswdPrompt("Password:");

session.login( loginname, password );

 

After opening the session successfully, send commands to the device using send method. It also has methods to set the Telnet socket timeout and the read buffer size using setSocketTimeout and setReadBufferLength respectively.

 

Please refer to Java documentation for complete details.

Related Topics

 



Copyright © 2009 ZOHO Corp. All Rights Reserved.