title: JSchException timeout: socket is not established
body: <p>I am trying to use <a href="http://www.jcraft.com/" rel="nofollow noreferrer">JSch</a> to connect to my computer through ssh and then run a command. </p>
  
  <p>However, when I run the code I never connect to the computer. and the following error: </p>
  
  <p><code>I/System.out: com.jcraft.jsch.JSchException: timeout: socket is not established</code></p>
  
  <p>Here is my relevant code:</p>
  
  <pre><code>protected void sshTesting(){
      String name = "";
      String userName = "kalenpw";
      String password = "hunter2";
      String ip = "192.168.0.4";
      int port = 22;
      String command = "cmus-remote -u";
  
      try{
          JSch jsch = new JSch();
          Session session = jsch.getSession(userName, ip, port);
          session.setPassword(password);
          session.setConfig("StrictHostKeyChecking", "no");
  
  
          System.out.println("Establishing connection");
          session.connect(10);
  
          Channel channel = session.openChannel("exec");
          ((ChannelExec)channel).setCommand(command);
          channel.setInputStream(null);
          channel.connect(10000);
  
  //            name = session.getUserName();
  //            System.out.println(session.getHost());
  
  
      }
      catch(Exception e){
          System.err.print(e);
          System.out.print(e);
      }        
  
  }
  </code></pre>
  
  <p>This is my first time using JSch so I am pretty much just following one of their examples <a href="http://www.jcraft.com/jsch/examples/Exec.java.html" rel="nofollow noreferrer">Exec.java</a>. I have found this answer <a href="https://stackoverflow.com/questions/6819246/jsch-sshj-connecting-to-ssh-server-on-button-click">JSch/SSHJ - Connecting to SSH server on button click</a> which unfortunately my code looks like it is establishing a connection in a similar fashion yet with no results. I have tested SSHing into my computer normally and it works fine so I don't believe the issue is with the server, but with my code. </p>
  
  <p>Here is the entire stack trace:</p>
  
  <pre><code>W/System.err: com.jcraft.jsch.JSchException: timeout: socket is not establishedcom.jcraft.jsch.JSchException: timeout: socket is not established
  W/System.err:     at com.jcraft.jsch.Util.createSocket(Util.java:394)
  W/System.err:     at com.jcraft.jsch.Session.connect(Session.java:215)
  W/System.err:     at com.example.kalenpw.myfirstapp.RectangleClickActivity.sshTesting(RectangleClickActivity.java:97)
  W/System.err:     at com.example.kalenpw.myfirstapp.RectangleClickActivity$1.onCheckedChanged(RectangleClickActivity.java:56)
  W/System.err:     at android.widget.CompoundButton.setChecked(CompoundButton.java:165)
  W/System.err:     at android.widget.Switch.setChecked(Switch.java:1151)
  W/System.err:     at android.widget.Switch.toggle(Switch.java:1146)
  W/System.err:     at android.widget.CompoundButton.performClick(CompoundButton.java:123)
  W/System.err:     at android.view.View$PerformClick.run(View.java:22589)
  W/System.err:     at android.os.Handler.handleCallback(Handler.java:739)
  W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
  W/System.err:     at android.os.Looper.loop(Looper.java:148)
  W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:7325)
  W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
  W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
  W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
  </code></pre>
  
  <p><code>RectangleClickActivity.java</code> is the file I am testing SSH.</p>
  
  <p>line 97 is: <code>session.connect(10);</code></p>
  
  <p>line 56 is: <code>sshTesting();</code></p>