Example #1
0
        public void StartReceive()
        {
            if (false == IsConnected())
            {
                ForceDisconnect(CloseReason.NotConnected);
                m_bReceiving.ForceFalse();
                return;
            }

            try
            {
                bool willRaiseEvent = m_socket.ReceiveAsync(m_saeaReciver);

                m_bReceiving.ForceTrue();

                // I/O 작업이 동기적으로 완료된 경우 false를 반환합니다.
                // 이 경우에는 e 매개 변수에서 SocketAsyncEventArgs.Completed 이벤트가 발생하지 않으며,
                // 메서드 호출이 반환된 직후 매개 변수로 전달된 e 개체를 검사하여 작업 결과를 검색할 수 있습니다.
                if (false == willRaiseEvent)
                {
                    ProcessReceive(m_saeaReciver);
                }
            }
            catch (Exception ex)
            {
                OnError(string.Format("StartReceive {0}", ex.ToString()));
                m_bReceiving.ForceFalse();
                ForceDisconnect(CloseReason.SocketError);
                return;
            }
        }
Example #2
0
        public void StartSend()
        {
            if (false == IsConnected())
            {
                return;
            }
            if (m_queueSend.Count <= 0)
            {
                return;
            }

            // send 할 때 setTrue를 하지 못하는 경우가 발생 보내지마.
            if (false == m_bSending.SetTrue())
            {
                return;
            }

            try
            {
                m_listSend.Clear();

                ArraySegment <byte> arrSegment;
                while (m_queueSend.TryDequeue(out arrSegment))
                {
                    m_listSend.Add(arrSegment);
                }

                m_saeaSender.BufferList = m_listSend;

                bool willRaiseEvent = m_socket.SendAsync(m_saeaSender);

                // I/O 작업이 동기적으로 완료된 경우 false를 반환합니다.
                // 이 경우에는 e 매개 변수에서 SocketAsyncEventArgs.Completed 이벤트가 발생하지 않으며,
                // 메서드 호출이 반환된 직후 매개 변수로 전달된 e 개체를 검사하여 작업 결과를 검색할 수 있습니다.
                if (false == willRaiseEvent)
                {
                    ProcessSend(m_saeaSender);
                }
            }
            catch (Exception ex)
            {
                OnError(string.Format("StartReceive {0}", ex.ToString()));
                m_bSending.ForceFalse();
                ForceDisconnect(CloseReason.SocketError);
                return;
            }
        }