Package com.tailf.ned
Class TelnetSession
Object
com.tailf.ned.TelnetSession
- All Implemented Interfaces:
CliSession
A telnet transport.
Example:
TelnetSession c = new TelnetSession("127.0.0.1", 23);
-
Constructor Summary
ConstructorDescriptionTelnetSession
(NedWorker worker) Constructor for Telnet session object.TelnetSession
(NedWorker worker, int readTimeout, NedTracer tracer, NedConnectionBase conn) Constructor with an extra argument for a readTimeout timer.TelnetSession
(NedWorker worker, NedTracer tracer, NedConnectionBase conn) Constructor for Telnet session object.TelnetSession
(NedWorker worker, String username, int readTimeout, NedTracer tracer, NedConnectionBase conn) Constructor with extra user name argument.TelnetSession
(String host, int port) Deprecated.TelnetSession
(String host, int port, int readTimeout, NedTracer tracer, NedConnectionBase conn) Deprecated.TelnetSession
(String host, int port, NedTracer tracer, NedConnectionBase conn) Deprecated.TelnetSession
(String host, int port, String username, int readTimeout, NedTracer tracer, NedConnectionBase conn) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Read from socket until Pattern is encountered.Read from socket until Pattern is encountered.Read from socket until Pattern is encountered.Read from socket until Pattern is encountered.void
flush()
Signals that the final chunk of data has be printed to the output transport stream.Needed by users that need to monitor a socket for EOF .void
Prints text to the output stream.void
Print text to the output stream.boolean
ready()
Tell whether this transport is ready to be read.boolean
ready
(int timeout) boolean
given a live session, check if the server side has closed it's end of the socket.void
setScreenSize
(int width, int length) void
void
-
Constructor Details
-
TelnetSession
Constructor for Telnet session object. This method creates a a new telnet session on top of an existing connection. Telnet objects implement the Transport interface and they are passed into the constructor of the NetconfSession class.- Parameters:
worker
- current NedWorker object- Throws:
IOException
-
TelnetSession
Deprecated.Note this method is deprecated, use Telnet(NedWorker) instead. Constructor for Telnet session object. This method creates a a new telnet session on top of an existing connection. Telnet objects implement the Transport interface and they are passed into the constructor of the NetconfSession class.- Throws:
IOException
-
TelnetSession
Constructor for Telnet session object. This method creates a a new telnet connection.- Parameters:
worker
- current NedWorker objecttracer
- Ned tracerconn
- NedConnection object- Throws:
IOException
-
TelnetSession
@Deprecated public TelnetSession(String host, int port, NedTracer tracer, NedConnectionBase conn) throws IOException Deprecated.Note this method is deprecated, use Telnet(NedWorker, NedTracer, NedConnection) instead. Constructor for Telnet session object. This method creates a a new telnet connection.- Throws:
IOException
-
TelnetSession
public TelnetSession(NedWorker worker, int readTimeout, NedTracer tracer, NedConnectionBase conn) throws IOException Constructor with an extra argument for a readTimeout timer.- Parameters:
worker
- current NedWorker objectreadTimeout
- timeout in millisecondstracer
- Ned tracerconn
- NedConnection object- Throws:
IOException
-
TelnetSession
@Deprecated public TelnetSession(String host, int port, int readTimeout, NedTracer tracer, NedConnectionBase conn) throws IOException Deprecated.Note this method is deprecated, use Telnet(NedWorker, int, NedTracer, NedConnection) instead. Constructor with an extra argument for a readTimeout timer.- Parameters:
host
-port
-readTimeout
- Time to wait for read. (in milliseconds)tracer
-conn
-- Throws:
IOException
-
TelnetSession
public TelnetSession(NedWorker worker, String username, int readTimeout, NedTracer tracer, NedConnectionBase conn) throws IOException Constructor with extra user name argument.- Parameters:
worker
- current NedWorker objectusername
-readTimeout
- timeout in millisecondstracer
- Ned tracerconn
- NedConnection object- Throws:
IOException
-
TelnetSession
@Deprecated public TelnetSession(String host, int port, String username, int readTimeout, NedTracer tracer, NedConnectionBase conn) throws IOException Deprecated.Note, this method is deprecated, use Telnet(NedWorker, String, int, NedTracer, NedConnection) instead.- Parameters:
host
-port
-username
-readTimeout
-tracer
-conn
-- Throws:
IOException
-
-
Method Details
-
setScreenSize
- Throws:
IOException
-
expect
Read from socket until Pattern is encountered.- Specified by:
expect
in interfaceCliSession
- Parameters:
Str
- is a regular expression pattern which is match against each line read.Include
- controls if the pattern should be include in the returned string or not.- Returns:
- the characters read.
- Throws:
IOException
-
expect
- Throws:
IOException
-
expect
- Throws:
IOException
-
expect
- Throws:
IOException
-
expect
Read from socket until Pattern is encountered.- Specified by:
expect
in interfaceCliSession
- Parameters:
Str
- is a regular expression pattern which is match against each line read.- Returns:
- the characters read.
- Throws:
IOException
-
expect
- Specified by:
expect
in interfaceCliSession
- Throws:
SSHSessionException
IOException
-
expect
- Specified by:
expect
in interfaceCliSession
- Throws:
IOException
-
expect
- Specified by:
expect
in interfaceCliSession
- Throws:
SSHSessionException
IOException
-
expect
Read from socket until Pattern is encountered.- Specified by:
expect
in interfaceCliSession
- Parameters:
Str
- is a regular expression pattern which is match against each line read.timeout
- indicates the read timeout- Returns:
- the characters read.
- Throws:
IOException
-
expect
- Specified by:
expect
in interfaceCliSession
- Throws:
IOException
-
expect
- Specified by:
expect
in interfaceCliSession
- Throws:
SSHSessionException
IOException
-
expect
- Specified by:
expect
in interfaceCliSession
- Throws:
IOException
-
expect
- Specified by:
expect
in interfaceCliSession
- Throws:
IOException
-
expect
- Specified by:
expect
in interfaceCliSession
- Throws:
IOException
-
expect
- Specified by:
expect
in interfaceCliSession
- Throws:
IOException
-
expect
public NedExpectResult expect(Pattern[] p, NedWorker worker) throws SSHSessionException, IOException - Specified by:
expect
in interfaceCliSession
- Throws:
SSHSessionException
IOException
-
expect
public NedExpectResult expect(String[] Str, boolean include, int timeout, NedWorker worker) throws IOException - Specified by:
expect
in interfaceCliSession
- Throws:
IOException
-
expect
public NedExpectResult expect(Pattern[] p, boolean include, int timeout, NedWorker worker) throws IOException - Specified by:
expect
in interfaceCliSession
- Throws:
IOException
-
expect
public NedExpectResult expect(Pattern[] p, boolean include, int timeout, boolean full) throws IOException - Throws:
IOException
-
expect
public NedExpectResult expect(Pattern[] p, boolean include, int timeout, boolean full, NedWorker worker) throws IOException - Throws:
IOException
-
expect
Read from socket until Pattern is encountered.- Specified by:
expect
in interfaceCliSession
- Parameters:
str
- is a regular expression pattern which is match against each line read.include
- controls if the pattern should be include in the returned string or not.full
- controls if the pattern should be matched against the entire line, or if a positive match is accepted whenever the pattern matches any substring on a line.- Returns:
- the characters read.
- Throws:
IOException
-
expect
public String expect(String str, boolean include, boolean full, int timeout, NedWorker worker) throws IOException - Specified by:
expect
in interfaceCliSession
- Throws:
IOException
-
close
public void close()- Specified by:
close
in interfaceCliSession
-
write
- Throws:
IOException
-
print
Prints text to the output stream.- Specified by:
print
in interfaceCliSession
- Parameters:
s
- Text to send to the stream.- Throws:
IOException
-
println
Print text to the output stream. A newline char is appended to end of the output stream.- Specified by:
println
in interfaceCliSession
- Parameters:
s
- Text to send to the stream.- Throws:
IOException
-
flush
Signals that the final chunk of data has be printed to the output transport stream. This method furthermore flushes the transport output stream buffer.- Specified by:
flush
in interfaceCliSession
- Throws:
IOException
-
getSocket
Needed by users that need to monitor a socket for EOF . This will return the underlying socket object. -
ready
Tell whether this transport is ready to be read.- Returns:
- true if there is something to read, false otherwise. This function can typically be used to poll a socket and see there is data to be read. Note that this method does not detect that the socket is in half-closed state and in such case will return false after timeout.
- Throws:
IOException
-
ready
- Throws:
IOException
-
serverSideClosed
public boolean serverSideClosed()given a live session, check if the server side has closed it's end of the socket. Note that it does not detect that the socket in half-closed state.- Specified by:
serverSideClosed
in interfaceCliSession
-
setTracer
- Specified by:
setTracer
in interfaceCliSession
-