Пример #1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 protected Byte[] GetResponseBytes(DataReceiveContext context)
 {
     this.GetResponseStream(context);
     return context.GetData();
 }
Пример #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        protected void GetResponseStream(DataReceiveContext context)
        {
            if (this.Socket == null)
            {
                throw new SocketClientException("Connection is closed");
            }
            using (var cx = context)
            {
                var bb = cx.Buffer;
                this.Stream.BeginRead(bb, 0, bb.Length, this.GetResponseCallback, cx);
                var bl = this.GetResponseDone.WaitOne(this.ReceiveTimeout);
                if (cx.Exception != null)
                {
                    throw cx.Exception;
                }
                if (cx.Timeout == true || bl == false)
                {
                    throw new SocketClientException("Response timeout");
                }

                if (TraceSource.Listeners.Count > 0)
                {
                    String text = this.ResponseEncoding.GetString(cx.GetData());
                    TraceSource.TraceInformation(String.Format("{0} Client Receive:{1}", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fffffff"), text));
                }
            }
        }
Пример #3
0
        /// 非同期でPOP3メールサーバーへコマンドを送信します。受信したレスポンスの文字列はcallbackFunctionの引数として取得できます。
        /// <summary>
        /// Send a command with asynchronous and get response text by first parameter of callbackFunction.
        /// 非同期でPOP3メールサーバーへコマンドを送信します。受信したレスポンスの文字列はcallbackFunctionの引数として取得できます。
        /// </summary>
        /// <param name="command"></param>
        /// <param name="context"></param>
        /// <param name="callbackFunction"></param>
        public void BeginSend(String command, DataReceiveContext context, Action<String> callbackFunction)
        {
            Boolean IsException = false;
            var cx = context;

            try
            {
                this.Send(command);
                var bb = cx.Buffer;
                this.Stream.BeginRead(bb, 0, bb.Length, this.BeginSendCallBack, cx);
            }
            catch
            {
                IsException = true;
                throw;
            }
            finally
            {
                if (IsException == true && cx != null)
                {
                    cx.Dispose();
                }
            }
        }