Example #1
0
        protected virtual void ReceiveMessage(SoketEventArgs e)
        {
            EventHandler <SoketEventArgs> handler = OnReceiveMessage;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Example #2
0
        private void CheckRecvMsg(byte[] recvByte, int i_recv)
        {
            byte[] tempRecv = RecvData.Take(i_recv).ToArray(); // 전체 바이트에서 실제로 수신된 바이트만 따로 골라낸다

            string sData          = Encoding.UTF8.GetString(tempRecv);
            string receiveMessage = sData.Replace("\0", "").Trim();

            SoketEventArgs args = new SoketEventArgs();

            args.EventTime    = DateTime.Now;
            args.Message      = receiveMessage;
            args.ProtocolType = Server.ProtocolType.ToString();
            args.EndPoint     = ep.ToString();

            OnReceiveMessage(args);               // 이벤트 전달
        }
Example #3
0
        void Receive_Completed(object sender, SocketAsyncEventArgs e)
        {
            Socket ClientSocket = (Socket)sender;

            if (ClientSocket.Connected && e.BytesTransferred > 0)
            {
                EndPoint tcpEp = ((System.Net.Sockets.Socket)(sender)).RemoteEndPoint;

                byte[] receiveData = e.Buffer;    // 데이터 수신
                string sData       = Encoding.UTF8.GetString(receiveData);

                string receiveMessage = sData.Replace("\0", "").Trim();
                //Console.WriteLine(string.Format("[{0}] : {1}", tcpEp.ToString(), "Test"));
                //Console.WriteLine(string.Format("{0}", receiveMessage));
                //Console.Write('#');

                SoketEventArgs args = new SoketEventArgs();
                args.EventTime    = DateTime.Now;
                args.Message      = receiveMessage;
                args.ProtocolType = ClientSocket.ProtocolType.ToString();
                args.EndPoint     = tcpEp.ToString();

                ReceiveMessage(args);               // 이벤트 전달


                for (int i = 0; i < receiveData.Length; i++)
                {
                    receiveData[i] = 0;
                }
                e.SetBuffer(receiveData, 0, receiveData.Length);

                ClientSocket.ReceiveAsync(e);
            }
            else
            {
                ClientSocket.Disconnect(false);
                ClientSocket.Dispose();
                m_ClientSocket.Remove(ClientSocket);
            }
        }
Example #4
0
        static void OnReceiveMeaasge(object sender, SoketEventArgs e)
        {
            logger.Info(string.Format("[{0}][{1}]{2}"
                                      , e.ProtocolType, e.EndPoint, e.Message));

            //string sReplyMessage = CmdExcute(e.Message.ToUpper());

            //if (sReplyMessage.Equals(string.Empty) == false)
            //{
            //    switch (e.ProtocolType.ToUpper())
            //    {
            //        case "TCP":
            //            string[] EndPoint = e.EndPoint.Split(':');
            //            tcpConnect.SendMessage(EndPoint[0], EndPoint[1], sReplyMessage);

            //            break;

            //        case "UDP":
            //            udpServer.SendResponse(Encoding.UTF8.GetBytes(sReplyMessage));
            //            break;
            //    }
            //}
        }