internal static SharpSsh.java.net.Socket createSocket(String host, int port, int timeout) { SharpSsh.java.net.Socket socket = null; String message = ""; if (timeout == 0) { try { socket = new SharpSsh.java.net.Socket(host, port); return(socket); } catch (Exception e) { message = e.ToString(); throw new JSchException(message); } } String _host = host; int _port = port; SharpSsh.java.net.Socket[] sockp = new SharpSsh.java.net.Socket[1]; Thread currentThread = Thread.CurrentThread; Exception[] ee = new Exception[1]; message = ""; createSocketRun runnable = new createSocketRun(sockp, ee, _host, _port); Thread tmp = new Thread(new ThreadStart(runnable.run)) { Name = "Opening Socket " + host }; tmp.Start(); try { tmp.Join(timeout); message = "timeout: "; } catch (ThreadInterruptedException eee) { } if (sockp[0] != null && sockp[0].isConnected()) { socket = sockp[0]; } else { message += "socket is not established. Please check your username, password or port"; //if (ee[0] != null) //{ // message = ee[0].ToString(); //} tmp.Interrupt(); tmp = null; throw new JSchException(message); } return(socket); }
public void run() { sockp[0] = null; try { sockp[0] = new SharpSsh.java.net.Socket(_host, _port); } catch (Exception e) { ee[0] = e; if (sockp[0] != null && sockp[0].isConnected()) { try { sockp[0].close(); } catch (Exception eee) { } } sockp[0] = null; } }
public void run() { sockp[0]=null; try { sockp[0]=new SharpSsh.java.net.Socket(_host, _port); } catch(Exception e) { ee[0]=e; if(sockp[0]!=null && sockp[0].isConnected()) { try { sockp[0].close(); } catch(Exception eee){} } sockp[0]=null; } }
internal static SharpSsh.java.net.Socket createSocket(String host, int port, int timeout) { SharpSsh.java.net.Socket socket=null; String message=""; if(timeout==0) { try { socket=new SharpSsh.java.net.Socket(host, port); return socket; } catch(Exception e) { message=e.ToString(); throw new JSchException(message); } } String _host=host; int _port=port; SharpSsh.java.net.Socket[] sockp=new SharpSsh.java.net.Socket[1]; Thread currentThread=Thread.CurrentThread; Exception[] ee=new Exception[1]; message=""; createSocketRun runnable = new createSocketRun(sockp, ee, _host, _port); Thread tmp=new Thread(new ThreadStart(runnable.run)); tmp.Name = "Opening Socket "+host; tmp.Start(); try { tmp.Join(timeout); message="timeout: "; } catch(ThreadInterruptedException eee) { } if(sockp[0]!=null && sockp[0].isConnected()) { socket=sockp[0]; socket.runThread = tmp; } else { message+="socket is not established"; if(ee[0]!=null) { message=ee[0].ToString(); } tmp.Interrupt(); tmp=null; throw new JSchException(message); } return socket; }