Esempio n. 1
0
        public int m_port;          //Port Number

        /*********************************
         *
         *           Constructor
         *
         **********************************/
        public Form1()
        {
            InitializeComponent();
            m_clientClass = new SocketClass();
            m_err         = new ErrProcess();
            m_asyncObject = new AsyncObjectClass(1024);
            m_ip          = string.Empty;
            m_port        = 0;
        }
Esempio n. 2
0
        /*********************************
         *
         *    Receive Call Back Event
         *
         **********************************/
        void ReceiveCallBack(IAsyncResult ar)
        {
            ERR_RESULT result = new ERR_RESULT();

            try
            {
                m_asyncObject = (AsyncObjectClass)ar.AsyncState;
                m_client      = m_asyncObject.WorkingSocket;
                Byte[]        RecvBuffer; //받은 메시지를 저장할 바이트 배열
                StringBuilder stringbuild = new StringBuilder();

                int ReadByteSize = m_client.EndReceive(ar); //받은 데이터 크기

                string[] str = new string[ReadByteSize];

                RecvBuffer = new Byte[ReadByteSize];                        //크기만큼 바이트 배열 동적 할당

                Array.Copy(m_asyncObject.Buffer, RecvBuffer, ReadByteSize); //ReadBuffer(전역)에 복사

                for (int i = 0; i < ReadByteSize; i++)
                {
                    str[i] = Convert.ToString(RecvBuffer[i], 16);
                }

                string msg = string.Empty;

                for (int i = 0; i < str.Length; i++)
                {
                    if (str[i].Length != 2)
                    {
                        msg += "0" + str[i] + " ";
                    }
                    else
                    {
                        msg += str[i] + " ";
                    }
                }

                stringbuild.Append("Response : " + msg + Environment.NewLine);

                string str2 = string.Empty;

                for (int i = 7; i > 0; i--)
                {
                    str2 += msg[msg.Length - i];
                }

                if (str[7] == "1" || str[7] == "2" || str[7] == "3")
                {
                    stringbuild.Append("Data : " + str2 + Environment.NewLine);
                }

                if (ReadByteSize > 0)                                                     //들어온 메시지가 있는 경우
                {
                    this.Invoke(new del_thread(InputText), new object[] { stringbuild }); //텍스트 입력
                }
            }
            catch (_MainException err)
            {
                result = ErrProcess.SetErrResult(err);
                m_err.SetErrCall(result);
            }
            catch (Exception err)
            {
                result = ErrProcess.SetErrResult(err);
                m_err.SetErrCall(result);
            }
        }