Example #1
0
        /*********************************
         *
         *    Receive Call Back Function
         *
         **********************************/
        void DataReceived(IAsyncResult ar)
        {
            ERR_RESULT result = new ERR_RESULT();

            try
            {
                m_asyncObject = (AsyncObjectClass)ar.AsyncState;
                Byte[] recvByte;                                           //받은 데이터 바이트 배열

                int RecvSize = m_asyncObject.WorkingSocket.EndReceive(ar); //받은 메시지 크기
                recvByte = new Byte[RecvSize];                             //크기만틈 배열 동적 할당

                Array.Copy(m_asyncObject.Buffer, recvByte, RecvSize);

                m_recvData = System.Text.Encoding.Default.GetString(recvByte);                                                         //Byte Array -> String

                WriteLogMsg(m_recvData);                                                                                               //받은 메시지 출력

                m_asyncObject.ClearBuffer();                                                                                           //버퍼 비우기

                ReturnClientSignal();                                                                                                  //Message 보내는 함수 호출

                m_asyncObject.WorkingSocket.BeginReceive(m_asyncObject.Buffer, 0, m_asyncObject.Size, 0, DataReceived, m_asyncObject); //다시 메세지를 받을 준비
            }
            catch (_MainException err)
            {
                result = ErrProcess.SetErrResult(err);
                m_err.SetErrCall(result);
            }
            catch (Exception err)
            {
                result = ErrProcess.SetErrResult(err);
                m_err.SetErrCall(result);
            }
        }
Example #2
0
        public string m_recvData;              //Receive Data

        /*********************************
         *
         *           Constructor
         *
         **********************************/
        public Form1()
        {
            InitializeComponent();
            m_SocketClass = new SocketServer();
            m_asyncObject = new AsyncObjectClass(1024);
            m_clientList  = new List <Socket>();
            m_err         = new ErrProcess();
            m_recvData    = string.Empty;
        }