public class Ssh2Channel extends SshAbstractChannel
All terminal sessions, forwarded connections, etc are channels and this class implements the base SSH2 channel. Either side may open a channel and multiple channels are multiplexed into a single SSH connection. SSH2 channels are flow controlled, no data may be sent to a channel until a message is received to indicate that window space is available.
To open a channel, first create an instance of the channel as follows:
The second value passed into the constructor is the initial window space and also the maximum amount of window space that will be available to the other side. The channel manages the window space automatically by increasing the amount available once the data has been read from the channels InputStream and only when the current value falls below half of the maximum.Ssh2Channel channel = new Ssh2Channel("session", 32768, 32768);
After the channel has been created the channel is opened through a call to openChannel(Ssh2Channel channel). Once the channel is open you can use the IO streams to send and receive data.
Modifier and Type | Field and Description |
---|---|
static String |
SESSION_CHANNEL |
CHANNEL_CLOSED, CHANNEL_OPEN, CHANNEL_UNINITIALIZED, channelid, manager, ms, state
Constructor and Description |
---|
Ssh2Channel(String name,
int windowsize,
int packetsize) |
Modifier and Type | Method and Description | ||
---|---|---|---|
void |
addChannelEventListener(ChannelEventListener listener)
Provides an event listening mechanism.
|
||
protected void |
channelEOF()
Called when the remote side data stream is EOF, by default this method
does nothing
|
||
protected void |
channelRequest(String requesttype,
boolean wantreply,
byte[] requestdata)
Called when a channel request is received, by default this method sends a
failure message if the remote side requests a reply.
|
||
protected void |
checkCloseStatus(boolean remoteClosed) |
||
void |
close()
Closes the channel.
|
||
protected byte[] |
create()
Called after the channel has been created by the
protected com.maverick.ssh2.Ssh2Channel.ChannelInputStream createExtendedDataStream()
Currently reserved.
| ||
boolean |
equals(Object obj)
This channel is equal to another channel if the channel id's are equal.
|
||
protected void |
free() |
||
SshClient |
getClient()
The SshClient that this channel belongs to
|
||
com.maverick.ssh2.ConnectionProtocol |
getConnection() |
||
InputStream |
getInputStream()
Get an InputStream to read incoming channel data.
|
||
int |
getMaximumLocalPacketLength()
The maximum packet length supported by this channel.
|
||
long |
getMaximumLocalWindowSize() |
||
int |
getMaximumRemotePacketLength()
The maximum packet length supported by this channel.
|
||
long |
getMaximumRemoteWindowSize() |
||
protected SshMessageStore |
getMessageStore() |
||
String |
getName()
Get the name of the channel.
|
||
OutputStream |
getOutputStream()
Get an OutputStream to write outgoing channel data.
|
||
long |
getRemoteWindow() |
||
protected MessageObserver |
getStickyMessageIds() |
||
void |
idle() |
||
boolean |
isSendKeepAliveOnIdle() |
||
protected void |
open(int remoteid,
long remotewindow,
int remotepacket)
Called once an SSH_MSG_CHANNEL_OPEN_CONFIRMATION has been sent.
|
||
protected void |
open(int remoteid,
long remotewindow,
int remotepacket,
byte[] responsedata)
Once a SSH_MSG_CHANNEL_OPEN_CONFIRMATION message is received the
framework calls this method to complete the channel open operation.
|
||
protected boolean |
processChannelMessage(SshChannelMessage msg)
Processes channel request messages by passing the request through to channelRequest()
.
|
||
protected void |
processExtendedData(int typecode,
int length,
SshChannelMessage msg)
Called when extended data arrives.
|
||
protected void |
processStandardData(int length,
SshChannelMessage msg)
Called when channel data arrives, by default this method makes the data
available in the channels InputStream.
|
||
void |
removeChannelEventListener(ChannelEventListener listener)
Provides an event listening mechanism.
|
||
boolean |
sendRequest(String requesttype,
boolean wantreply,
byte[] requestdata)
Sends a channel request.
|
||
boolean |
sendRequest(String requesttype,
boolean wantreply,
byte[] requestdata,
boolean isActivity)
Sends a channel request.
|
||
void |
setAutoConsumeInput(boolean autoConsumeInput)
Automatically consume input data
|
||
void |
setSendKeepAliveOnIdle(boolean sendKeepAliveOnIdle) |
getChannelId, getMessageRouter, init, isClosed, waitForOpen
public static final String SESSION_CHANNEL
public Ssh2Channel(String name, int windowsize, int packetsize)
public SshClient getClient()
SshChannel
public com.maverick.ssh2.ConnectionProtocol getConnection()
protected MessageObserver getStickyMessageIds()
getStickyMessageIds
in class SshAbstractChannel
public void setAutoConsumeInput(boolean autoConsumeInput)
SshChannel
autoConsumeInput
- booleanprotected SshMessageStore getMessageStore() throws SshException
getMessageStore
in class SshAbstractChannel
SshException
public String getName()
public InputStream getInputStream()
SshIO
public OutputStream getOutputStream()
SshIO
public void addChannelEventListener(ChannelEventListener listener)
SshChannel
public void removeChannelEventListener(ChannelEventListener listener)
SshChannel
public boolean isSendKeepAliveOnIdle()
public void setSendKeepAliveOnIdle(boolean sendKeepAliveOnIdle)
public void idle()
idle
in class SshAbstractChannel
protected byte[] create()
IOException
protected void open(int remoteid, long remotewindow, int remotepacket) throws IOException
remoteid
- remotewindow
- remotepacket
- IOException
public int getMaximumRemotePacketLength()
SshChannel
public int getMaximumLocalPacketLength()
SshChannel
public long getMaximumLocalWindowSize()
public long getMaximumRemoteWindowSize()
protected void open(int remoteid, long remotewindow, int remotepacket, byte[] responsedata) throws IOException
remoteid
- the senders idremotewindow
- the initial window space available for sending dataremotepacket
- the maximum packet size available for sending dataresponsedata
- the data returned from the remote side in the
SSH_MSG_CHANNEL_OPEN_CONFIRMATION messageIOException
protected boolean processChannelMessage(SshChannelMessage msg) throws SshException
processChannelMessage
in class SshAbstractChannel
SshException
protected void processStandardData(int length, SshChannelMessage msg) throws SshException
buf
- offset
- len
- IOException
SshException
protected void processExtendedData(int typecode, int length, SshChannelMessage msg) throws SshException
com.maverick.ssh.ChannelEventListener#extendedDataReceived(com.maverick.ssh.Channel, byte[], int, int, int)
event so to maintain code compatibility always call the super
method in any overidden method.typecode
- the type of extended databuf
- the data bufferoffset
- the offsetlen
- the lengthSshException
IOException
protected com.maverick.ssh2.Ssh2Channel.ChannelInputStream createExtendedDataStream()
public boolean sendRequest(String requesttype, boolean wantreply, byte[] requestdata) throws SshException
requesttype
- the name of the request, for example "pty-req"wantreply
- specifies whether the remote side should send a
success/failure messagerequestdata
- the request datatrue
if the request succeeded and wantreply=true,
otherwise false
IOException
SshException
public boolean sendRequest(String requesttype, boolean wantreply, byte[] requestdata, boolean isActivity) throws SshException
requesttype
- the name of the request, for example "pty-req"wantreply
- specifies whether the remote side should send a
success/failure messagerequestdata
- the request dataisActivity
- true
if the request succeeded and wantreply=true,
otherwise false
IOException
SshException
public long getRemoteWindow()
public void close()
protected void checkCloseStatus(boolean remoteClosed)
protected void free()
public boolean equals(Object obj)
protected void channelRequest(String requesttype, boolean wantreply, byte[] requestdata) throws SshException
requesttype
- the name of the requestwantreply
- specifies whether the remote side requires a success/failure
messagerequestdata
- the request dataIOException
SshException
protected void channelEOF()
IOException
Copyright © 2024. All rights reserved.