Ejemplo n.º 1
0
        /// <summary>
        /// Description of Listener.
        /// <param name="on_recv" type="RecvHandler(String s)">收到数据后要调用的函数委托</param>
        /// <returns>调用委托函数处理处理数据后返回的结果</returns>
        /// </summary>
        public Listener(RecvHandler on_recv)
        {
            FileStream   fs = new FileStream(file, FileMode.Open);
            StreamReader sr = new StreamReader(fs);

            _listener = new System.Net.HttpListener();
            On_recv   = on_recv;
            _listener.Prefixes.Add(sr.ReadLine().Trim());
            _listener.Start();
            Start();
        }
Ejemplo n.º 2
0
 private IEnumerator ProcPacketQueue(Queue <IPacket> packets, Protocol p)
 {
     while (true)
     {
         int c = 0;
         while (packets.Count > 0 && c < 100000)
         {
             c++;
             IPacket data = packets.Dequeue();
             Debug.Log("<color=red>" + data.GetType() + "</color>", gameObject);
             RecvHandler?.Invoke(data, p);
             //_gm.ProcessPacket(packets.Dequeue());
         }
         yield return(new WaitForFixedUpdate());
     }
 }
Ejemplo n.º 3
0
        public static void BeginReceive(Socket handler, RecvHandler onRecv)
        {
            var stateObject = new StateObject()
            {
                workSocket = handler,
                onRecv     = onRecv
            };

            try
            {
                handler.BeginReceive(
                    stateObject.buffer, 0, StateObject.BufferSize, 0,
                    new AsyncCallback(ReadCallback), stateObject);
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
                onRecv(null, 0);
            }
        }
Ejemplo n.º 4
0
 public Pipe(StreamReader S, RecvHandler H)
 {
     s = S;
     h = H;
 }