Beispiel #1
0
        /// <summary>
        /// 非同期受信
        /// </summary>
        /// <param name="size"></param>
        public void ReciveAsync(int size)
        {
            // 接続中か?
            if (!this.m_Client.IsConnected)
            {
                // 例外
                throw new SshClientException("接続状態(SSH)ではありません");
            }

            // 受信用Stream生成
            SshClientReciveStream stream = new SshClientReciveStream();

            stream.Buffer         = new byte[size];
            stream.ConnectionInfo = this.m_ConnectionInfo;
            stream.IPEndPoint     = this.m_IPEndPoint;
            stream.ShellStream    = this.m_ShellStream;
            stream.SshClient      = this.m_Client;
            stream.Stream         = new MemoryStream(size);

            // 非同期受信
            IAsyncResult result = this.m_ShellStream.BeginRead(stream.Buffer, 0, stream.Buffer.Length, this.ReciveAsyncCallback, stream);
        }
Beispiel #2
0
        /// <summary>
        /// 非同期受信コールバック
        /// </summary>
        /// <param name="ar"></param>
        private void ReciveAsyncCallback(IAsyncResult ar)
        {
            // オブジェクト変換
            SshClientReciveStream stream = (SshClientReciveStream)ar.AsyncState;

            // 非同期読込が終了
            int bytesRead = stream.ShellStream.EndRead(ar);

            System.Console.WriteLine("受信(非同期)データサイズ:{0}", bytesRead);

            // ロギング
            this.Logger.InfoFormat("受信(非同期)データ - {0:#,0} byte:\n{1}", bytesRead, Common.Diagnostics.Debug.Dump(1, stream.Buffer, bytesRead));

            // 受信通知
            this.OnReciveNotify.Set();

            // イベント呼出
            if (this.OnRecive != null)
            {
                // イベントパラメータ生成
                SshClientReciveEventArgs eventArgs = new SshClientReciveEventArgs()
                {
                    ConnectionInfo = stream.ConnectionInfo,
                    Size           = bytesRead,
                    Stream         = stream.Stream,
                };

                // イベント呼出し
                this.OnRecive(this, eventArgs);
            }

            // ShellStreamフラッシュ
            stream.ShellStream.Flush();

            // 受信通知リセット
            this.OnReciveNotify.Reset();
        }