Ejemplo n.º 1
0
        /// <summary>
        /// 非同期送信コールバック
        /// </summary>
        /// <param name="ar"></param>
        private void SendCallBack(IAsyncResult ar)
        {
            // オブジェクト変換
            TelnetClientSendStream stream = (TelnetClientSendStream)ar.AsyncState;

            // 送信完了
            int bytesSent = stream.Socket.EndSend(ar);

            // ロギング
            this.Logger.InfoFormat("送信データ - {0:#,0} byte:\n{1}", stream.Stream.Length, Common.Diagnostics.Debug.Dump(1, stream.Stream));

            // 送信通知
            this.OnSendNotify.Set();

            // イベント呼出
            if (this.OnSend != null)
            {
                // イベントパラメータ生成
                TelnetClientSendEventArgs eventArgs = new TelnetClientSendEventArgs()
                {
                    Socket = stream.Socket,
                    Size   = bytesSent,
                    Stream = stream.Stream,
                };

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

            // 送信通知リセット
            this.OnSendNotify.Reset();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 非同期送信
        /// </summary>
        /// <param name="stream"></param>
        public void SendAsync(MemoryStream stream)
        {
            // 接続中か?
            if (!this.m_Socket.Connected)
            {
                // 例外
                throw new TelnetClientException("接続状態(Telnet)ではありません");
            }

            // 送信用Stream生成
            TelnetClientSendStream sendStream = new TelnetClientSendStream();

            sendStream.Socket = this.m_Socket;
            sendStream.Stream = stream;

            // 非同期送信
            IAsyncResult _result = this.m_Socket.BeginSend(stream.ToArray(), 0, stream.ToArray().Length, SocketFlags.None, new AsyncCallback(this.SendCallBack), sendStream);
        }