Exemple #1
0
        /// <summary>
        /// 数据包输入
        /// </summary>
        /// <param name="data">输入数据</param>
        /// <param name="socketAsync">该数据包的通讯SOCKET</param>
        static async void BinaryInputHandler(ISockAsyncEvent socketAsync)
        {
            var fiberRw = await socketAsync.GetFiberRw <string>();

            fiberRw.UserToken = "my is ttk";

            for (; ;)
            {
                try
                {
                    await DataOnByLine(fiberRw);
                }
                catch (System.Net.Sockets.SocketException)
                {
                    break;
                }
                catch (Exception er)
                {
                    Console.WriteLine(er.ToString());
                    break;
                }
            }

            socketAsync.Disconnect();
        }
Exemple #2
0
        /// <summary>
        /// 数据包输入
        /// </summary>
        /// <param name="data">输入数据</param>
        /// <param name="socketAsync">该数据包的通讯SOCKET</param>
        static async void BinaryInputHandler(ISockAsyncEvent socketAsync)
        {
            var fiberRw = await socketAsync.GetFiberRw <string>();

            fiberRw.UserToken = "my is ttk";

            for (; ;)
            {
                try
                {
                    //读取 发送 测试
                    var data = await fiberRw.ReadToBlockArrayEnd();

                    fiberRw.Write(data);
                    await fiberRw.FlushAsync();
                }
                catch (SocketException)
                {
                    break;
                }
                catch (Exception er)
                {
                    Console.WriteLine(er.ToString());
                    break;
                }

                //try
                //{
                //    //提供2种数据 读取写入方式
                //    using (ReadBytes readBytes = new ReadBytes(fiberRw))
                //    {
                //        await readBytes.Init();
                //        DataOn(readBytes, fiberRw);
                //    }


                //    await DataOnByLine(fiberRw);



                //}
                //catch (System.Net.Sockets.SocketException)
                //{
                //    break;
                //}
                //catch (Exception er)
                //{
                //    Console.WriteLine(er.ToString());
                //    break;
                //}
            }

            socketAsync.Disconnect();
        }