Пример #1
0
 public SocketAsyncResult(SocketBaseRequest request, SocketClient socketClient, AsyncCallback userCallback, object asyncState)
 {
     this._request      = request;
     this._socketClient = socketClient;
     this._userCallback = userCallback;
     this._asyncState   = asyncState;
     // 异步执行操作
     ThreadPool.QueueUserWorkItem((obj) => { AsyncRequest(obj); }, this);
 }
Пример #2
0
        public string Send(SocketBaseRequest request, SocketClient socketClient, ref string resultStr)
        {
            string _request = string.Empty;

            if (socketClient.SendRequest(request))
            {
                resultStr = _request = socketClient.Listen();
            }

            return(_request);
        }
Пример #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="request"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 public void SendRequestAsync(SocketBaseRequest request, SocketMessageInfoType type = SocketMessageInfoType.REQUEST)
 {
     if (this.connected)
     {
         string _str       = SerializeHelper.JsonSerializer(request);
         string message    = string.Format("[length={0}][MSG={1}]{2}", _str.Length, type.ToString(), _str);
         byte[] sendBuffer = Encoding.Unicode.GetBytes(message);
         SendData(sendBuffer);
     }
     else
     {
         throw new SocketException((int)SocketError.NotConnected);
     }
 }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="request"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public SocketBaseResponse <T> RequestAsync <T>(SocketBaseRequest request, AsyncCallback callback)
        {
            if (this.connected)
            {
                _readWirted.ReceiveSAEA.Completed -= OnReceive;

                SocketSendLib <T>      _sender      = new SocketSendLib <T>();
                IAsyncResult           _sendRequest = _sender.BeginSend(request, this, callback, _sender);
                string                 resultStr    = string.Empty;
                SocketBaseResponse <T> _result      = _sender.EndSend(ref resultStr, _sendRequest);

                _readWirted.ReceiveSAEA.Completed += OnReceive;
                return(_result);
            }
            else
            {
                throw new SocketException((int)SocketError.NotConnected);
            }
        }
Пример #5
0
        public IAsyncResult BeginSend(SocketBaseRequest request, SocketClient socketClient, AsyncCallback userCallback, object asyncState)
        {
            SocketAsyncResult <T> result = new SocketAsyncResult <T>(request, socketClient, userCallback, asyncState);

            return(result);
        }