Ejemplo n.º 1
0
        /*
         * public void finalize() throws Throwable{
         * disconnect();
         * super.finalize();
         * session=null;
         * }
         */

        public virtual void disconnect()
        {
            //System.Out.println(this+":disconnect "+io+" "+io.in);
            if (!connected)
            {
                return;
            }
            connected = false;

            close();

            _eof_remote = eof_local = true;

            thread = null;

            try
            {
                if (io != null)
                {
                    io.close();
                }
            }
            catch (Exception e)
            {
                //e.printStackTrace();
            }
            io = null;
            Channel.del(this);
        }
Ejemplo n.º 2
0
 public override void disconnect()
 {
     close();
     thread = null;
     try
     {
         if (io != null)
         {
             try
             {
                 if (io.ins != null)
                 {
                     io.ins.Close();
                 }
             }
             catch {}
             try
             {
                 if (io.outs != null)
                 {
                     io.outs.Close();
                 }
             }
             catch {}
         }
         try
         {
             if (socket != null)
             {
                 socket.Close();
             }
         }
         catch {}
     }
     catch (Exception e)
     {
         Console.WriteLine(e.StackTrace);
     }
     io = null;
     Channel.del(this);
 }
Ejemplo n.º 3
0
        public override void connect()
        {
            try
            {
                if (!session.isConnected())
                {
                    throw new JSchException("session is down");
                }
                Buffer buf    = new Buffer(150);
                Packet packet = new Packet(buf);
                // send
                // byte   SSH_MSG_CHANNEL_OPEN(90)
                // string channel type         //
                // uint32 sender channel       // 0
                // uint32 initial window size  // 0x100000(65536)
                // uint32 maxmum packet size   // 0x4000(16384)

                packet.reset();
                buf.putByte((byte)90);
                buf.putString(Util.getBytes("direct-tcpip"));
                buf.putInt(id);
                buf.putInt(lwsize);
                buf.putInt(lmpsize);
                buf.putString(Util.getBytes(host));
                buf.putInt(port);
                buf.putString(Util.getBytes(originator_IP_address));
                buf.putInt(originator_port);
                session.write(packet);

                int retry = 1000;
                try
                {
                    while (this.getRecipient() == -1 &&
                           session.isConnected() &&
                           retry > 0 &&
                           !_eof_remote)
                    {
                        //Thread.sleep(500);
                        Thread.Sleep(50);
                        retry--;
                    }
                }
                catch
                {
                }

                if (!session.isConnected())
                {
                    throw new JSchException("session is down");
                }
                if (retry == 0 || this._eof_remote)
                {
                    throw new JSchException("channel is not opened.");
                }

                /*
                 * if(this.eof_remote){      // failed to open
                 * disconnect();
                 * return;
                 * }
                 */

                connected = true;

                thread = new Thread(this);
                thread.start();
            }
            catch (Exception e)
            {
                io.close();
                io = null;
                Channel.del(this);
                if (e is JSchException)
                {
                    throw (JSchException)e;
                }
            }
        }