示例#1
0
    /// <summary>
    /// 发送心跳包
    /// </summary>
    /// *

    public bool sendHeadData()
    {
        MyDebug.Log("send head data");
        try{
            if (stream != null && tcpclient.Connected)
            {
                HeadRequest head = new HeadRequest();
                headBytes = head.ToBytes();
                stream.Write(headBytes, 0, headBytes.Length);

                return(true);
            }
            else
            {
                isConnected = false;
                SocketEventHandle.getInstance().noticeDisConect();
                return(false);
            }
        }catch (Exception ex) {
            MyDebug.Log(ex.ToString());
            isConnected = false;
            //showMessageTip ("服务器已断开连接,请重新登录");
            isConnected = false;
            SocketEventHandle.getInstance().noticeDisConect();
            return(false);
        }
    }
示例#2
0
        /// <summary>
        /// 验证数据是否被篡改,进行认证
        /// </summary>
        /// <param name="request"></param>
        /// <param name="data"></param>
        /// <param name="sign"></param>
        /// <returns></returns>
        public Tbl_OTABusiness CheckData(HeadRequest request, string data, string sign)
        {
            var business = _otaBusinessService.Get(request.InvokeUser);

            if (business == null)
            {
                return(null);
            }
            data = data.Replace(" ", "+");
            var    context = business.Saltcode.ToString().ToUpper() + data;
            string mySign  = Md5Helper.Md5Encrypt32(context);

            if (sign.ToUpper() != mySign.ToUpper())
            {
                return(null);
            }
            return(business);
        }
示例#3
0
    public ChatSocket()
    {
        HeadRequest head = new HeadRequest();

        headBytes = head.ToBytes();
    }
示例#4
0
        static async Task ObjectHead(ObjectHeadOptions opts)
        {
            byte[] cid;

            var key = privateKey.FromHex().LoadKey();

            try
            {
                cid = Base58.Decode(opts.CID);
            }
            catch (Exception err)
            {
                Console.WriteLine("wrong cid format: {0}", err.Message);
                return;
            }

            var channel = new Channel(opts.Host, ChannelCredentials.Insecure);

            channel.UsedHost().GetHealth(SingleForwardedTTL, key, opts.Debug).Say();

            var req = new HeadRequest
            {
                FullHeaders = opts.Full,
                Address     = new NeoFS.API.Refs.Address
                {
                    CID      = ByteString.CopyFrom(cid),
                    ObjectID = ByteString.CopyFrom(opts.OID.Bytes()),
                },
            };

            req.SetTTL(SingleForwardedTTL);
            req.SignHeader(key, opts.Debug);

            var res = new Service.ServiceClient(channel).Head(req);

            Console.WriteLine();

            Console.WriteLine("Received object headers");
            Console.WriteLine("\nSystemHeaders\n" +
                              "Version: {0}\n" +
                              "PayloadLength: {1}\n" +
                              "ObjectID: {2}\n" +
                              "OwnerID: {3}\n" +
                              "CID: {4}\n" +
                              "CreatedAt: {5}\n",
                              res.Object.SystemHeader.Version,
                              res.Object.SystemHeader.PayloadLength,
                              res.Object.SystemHeader.ID.ToUUID(),
                              res.Object.SystemHeader.OwnerID.ToAddress(),
                              res.Object.SystemHeader.CID.ToCID(),
                              res.Object.SystemHeader.CreatedAt);

            if (opts.Full)
            {
                Console.WriteLine("Headers:");
                for (var i = 0; i < res.Object.Headers.Count; i++)
                {
                    Console.WriteLine(res.Object.Headers[i]);
                }
                Console.WriteLine();
            }

            Console.WriteLine("Meta:\n{0}", res.Meta);
            await Task.Delay(TimeSpan.FromMilliseconds(100));
        }
示例#5
0
 public abstract void VisitHeadDescription(HeadRequest element);
示例#6
0
        public override void StartDownload(HttpPreparedDownload download)
        {
            Task.Run(() =>
            {
                DownloadRequest req = new DownloadRequest(download.Url, download.FilePath);

                downloads.TryAdd(download, req);

                if (download.FileSize == 0)
                {
                    try
                    {
                        StUtil.Net.HeadRequest head = new HeadRequest(download.Url)
                        {
                            Timeout = 5000
                        };
                        int sz = 0;
                        int.TryParse(head.Run()["Content-Length"], out sz);
                        download.FileSize = sz;
                    }
                    catch (Exception)
                    {
                        //Ignore head error
                    }
                }

                if (File.Exists(download.FilePath))
                {
                    download.BytesReceived = new FileInfo(download.FilePath).Length;
                    if (download.BytesReceived == 0)
                    {
                        File.Delete(download.FilePath);
                    }
                }

                bool unknownFileSize = download.FileSize == 0;
                if (download.BytesReceived < download.FileSize || unknownFileSize)
                {
                    req.Timeout        = 5000;
                    req.ResumePosition = download.BytesReceived;
                    req.TryIgnoreError = false;
                    req.DataReceived  += (sender, e) =>
                    {
                        download.BytesReceived = e.Value;
                        if (unknownFileSize)
                        {
                            download.FileSize = e.Value + (e.Value / 100);
                        }
                    };
                    req.Run();
                }
            }).ContinueWith(t =>
            {
                if (t.IsFaulted)
                {
                    download.LastError = t.Exception;
                    download.State     = DownloadState.Failed;
                }
                else if (downloads[download].Stop)
                {
                }
                else
                {
                    download.FileSize = download.BytesReceived;
                    download.State    = DownloadState.Completed;
                }
                Unblock(download);
            });
        }
示例#7
0
 public override void VisitHeadDescription(HeadRequest element)
 => _builder.MapMethods(element.Path, new [] { Head.Method }, RequestDelegate());