Ejemplo n.º 1
0
        internal async Task _Listener()
        {
            while (_cancel.IsCancellationRequested == false)
            {
                var soc = await _listen.AcceptAsyncEx();

                Task.Run(async() =>
                {
                    try
                    {
                        soc.SetKeepAlive();
                        var buf = await soc.ReceiveAsyncExt().TimeoutAfter("Timeout, at receive header packet.");
                        var pkt = new LinkPacket().LoadValue(buf);
                        await _requested.Invoke(soc, pkt);
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex);
                    }
                    finally
                    {
                        soc.Dispose();
                    }
                }).Ignore();
            }
        }
Ejemplo n.º 2
0
        public static LinkPacket LoadValue(this LinkPacket src, byte[] buf)
        {
            var ori = new Token(LinksHelper.Generator, buf);

            src._buffer = buf;
            src._origin = ori;
            src._source = ori["source"].As <int>();
            src._target = ori["target"].As <int>();
            src._path   = ori["path"].As <string>();
            src._data   = ori["data", nothrow : true];
            return(src);
        }
Ejemplo n.º 3
0
        public static LinkPacket LoadValue(this LinkPacket src, byte[] buf)
        {
            var ori = new PacketReader(buf);

            src._buf = buf;
            src._ori = ori;
            src._src = ori["source"].GetValue <int>();
            src._tar = ori["target"].GetValue <int>();
            src._pth = ori["path"].GetValue <string>();
            src._dat = ori["data", true];
            return(src);
        }
Ejemplo n.º 4
0
        internal async Task _Receiver()
        {
            while (_cancel.IsCancellationRequested == false)
            {
                var buf = await _socket.ReceiveAsyncExt();

                var rec = Received;
                if (rec == null)
                {
                    continue;
                }
                var res = _aes.Decrypt(buf);
                var pkt = new LinkPacket().LoadValue(res);
                var arg = new LinkEventArgs <LinkPacket>(pkt);
                rec.Invoke(this, arg);
            }
        }