コード例 #1
0
        private void ReadCB(IAsyncResult ar)
        {
            ReadStateObject state = (ReadStateObject)ar.AsyncState;

            if (!state.workSocket.Connected)
            {
                return;
            }

            int nReadSize = 0;

            try
            {
                nReadSize = state.workSocket.EndReceive(ar);
            }
            catch (Exception ex)
            {
                //System.Diagnostics.Debug.Print(ex.Message);
                OnMessageEvent(new MessageEventArgs(ex.Message, true));
            }

            if (0 < nReadSize)
            {
                string strQuery = Encoding.UTF8.GetString(state.buffer, 0, nReadSize);

                SocketEVentArgs e = new SocketEVentArgs();
                e.QueryString = strQuery;
                OnQueryEvent(e);
            }

            if (state.workSocket.Connected)
            {
                state.workSocket.BeginReceive(state.buffer, 0, ReadStateObject.BUFFER_SIZE, SocketFlags.None, ReadCB, state);
            }
        }
コード例 #2
0
        protected void OnQueryEvent(SocketEVentArgs e)
        {
            if (null == QueryEvent)
            {
                return;
            }

            QueryEvent(this, e);
        }