예제 #1
0
        /// <summary>
        /// düşen datayı yakalayacan metot
        /// </summary>
        /// <param name="server"></param>
        /// <param name="e"></param>
        public override void SessionReceive(IServer server, SessionReceiveEventArgs e)
        {
            try
            {
                TcpResponseModel tcpResponseModel = new TcpResponseModel()
                {
                    Result = "OK"
                };
                BeetleX.Buffers.PipeStream pipeStream = e.Stream.ToPipeStream();
                using (MemoryStream memoryStream = new MemoryStream(pipeStream.FirstBuffer.Data)) //pipeStream1.LastBuffer.Data
                    using (StreamReader reader = new StreamReader(memoryStream))
                    {
                        var data = reader.ReadToEnd();
                        if (!string.IsNullOrEmpty(data))
                        {
                            TcpInit.GetIntance().TcpDataReceived(data, null);
                        }

                        pipeStream.Write(@"{""result"":""OK""}!");
                        e.Session.Stream.Flush();
                        base.SessionReceive(server, e);
                    }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{ex + "TcpConsumer/SessionReceive"}");
            }
        }
예제 #2
0
 /// <summary>
 /// tcp getinstance meetodu clası buradan dışarı açıyoruz(Constructor burdan tetikleniyor)
 /// </summary>
 /// <param name="host"></param>
 /// <param name="port"></param>
 /// <returns></returns>
 public static TcpInit GetIntance()
 {
     if (tcpInit == null)
     {
         tcpInit = new TcpInit();
     }
     return(tcpInit);
 }
예제 #3
0
 static void Main(string[] args)
 {
     TcpInit.GetIntance().StartConsume();
     TcpInit.GetIntance().DataReceived += Program_DataReceived;
     Console.ReadLine();
 }