I've being teached myself Java over the last few weeks (quite possibly doing something wrong)!
I have developed a simple program that connects to a database lists locations. I can connect to them, using JSCH to set up a tunnel. So I can VNC onto it.
This all works fine. However, my issue is with the disconnect part of this.
I have a Public Void called WinConnect, this is fired if the button for connection had been clicked cliked and as above works as thread.
On the disconnect button I tried:
Current Part of the relivant button code
private void jButtonDisconnectActionPerformed(java.awt.event.ActionEvent evt) {
this.channel.disconnect();
this.session.disconnect();
}
Session session.disconnect(); //says expected; and cannot find symbol
method disconnect
Session.session.disconnect(); //this says cannot find varible session
JSch.session.disconnect //this says cannot find varible session
and so on, none of them do work. Netbeans says there are errors within the code. Clearly my lack of knowledge means im doing something wrong, probably something obvious!
All Of WinConnect:
private void WinConnect(){
String SshPortNumb = (String)SshPort.getSelectedItem();
int SshPortNum = Integer.parseInt(SshPortNumb);
String PcIpNum = (String)PcIp.getText();
String host = (String)SiteIp.getText();
String VncPortNumb = VncPort.getText();
int VncPortNum = Integer.parseInt(VncPortNumb);
String user = (String)UserName.getText();
String PasswordVal = (String)Password.getText();
String VncPathpre = VncPath.getText();
String VncPathdat = "\""+VncPathpre+"\"";
try{
JSch jsch=new JSch();
jsch.setKnownHosts("known_hosts");
this.session=jsch.getSession(user, host, SshPortNum);
String passwd = PasswordVal;
this.session.setPassword(passwd);
UserInfo ui = new MyUserInfo(){
public void showMessage(String message){
JOptionPane.showMessageDialog(null, message);
}
public boolean promptYesNo(String message){
Object[] options={ "yes", "no" };
int foo=JOptionPane.showOptionDialog(null,
message,
"Warning",
JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE,
null, options, options[0]);
return foo==0;
}
};
jButtonDisconnect.setEnabled(true);
jButtonConnect.setEnabled(false);
this.session.setUserInfo(ui);
this.session.connect(30000);
this.session.setPortForwardingL(7051, PcIpNum, VncPortNum);
this.channel=session.openChannel("shell");
this.channel.setInputStream(System.in);
this.channel.setOutputStream(System.out);
this.channel.connect(3*1000);
}
catch(Exception e){
System.out.println(e);
}
}
public class RemoteDesktop extends javax.swing.JFrame {
private Session session;
private Channel channel;
EDIT: Guess because the varible Session is in the winconnect and not in the button it can't find it?
Edit2: After trying suggestion below it just locks up when clicking disconnect
Edit3: Right the new code should work, but there appears to be an issue with session.disconnect, if i call session.delPortForwardingL(7051); it works but im not sure if the connections are still active, unsure why session.disconnect does not!
Edit4: Checked the server and the connecetions are still in place it does just remove the fowarding stoppign my VNC, not good :(
Edit5: Checked if calling the session.disconnect was actually working it does, it however causes my program to lock up for some reason