public void Connect(string ip, int port) { System.Net.IPAddress[] ips = System.Net.Dns.GetHostAddresses(ip); if (null != ips && ips.Length > 0) { if (m_client != null) { m_client.Close(); } this.InitNetClient(); this.ip = ip; this.port = port; m_client.Connect(ips[0].ToString(), port); NetSpeed.SetIp(ips[0].ToString()); } }
public void TestMethod1() { var sw = new Stopwatch(); sw.Start(); var ns = new NetSpeed(); sw.Stop(); WriteHelper.Log($"初始化耗时:{sw.ElapsedMilliseconds}ms"); for (var i = 0; i < 5; i++) { sw.Restart(); var sent = ns.GetSentSpeed(); var revice = ns.GetReceivedSpeed(); sw.Stop(); WriteHelper.Log($"接收:{revice}kb;发送:{sent}kb;耗时:{sw.ElapsedMilliseconds}ms"); Thread.Sleep(1000); } }
public override string ToString() { return($"DataCode={DataCode},CoinCode={CoinCode},Speed={Speed.ToString()},SpeedUnit={SpeedUnit},IncomeCoin={IncomeCoin.ToString()},IncomeUsd={IncomeUsd.ToString()},IncomeCny={IncomeCny.ToString()},NetSpeed={NetSpeed.ToString()},NetSpeedUnit={NetSpeedUnit}"); }
public void InitDownloadHttp() { try { if (m_remoteLength > 0) { SendToLua(m_localLength, m_remoteLength); return; } string path = PathUtils.MakeFilePath("http_zip.zip", PathUtils.PathType.MobileDiskWrite); string url = GameConfig.HOST_RES() + "http_zip.zip"; FileStream stream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite); HTTPRequest http = new BestHTTP.HTTPRequest(new Uri(url), HTTPMethods.Head, (req, resp) => { if (resp == null) { stream.Dispose(); return; } if (resp.StatusCode == 416) { stream.Dispose(); return; } if (resp.HasHeaderWithValue("accept-ranges", "none")) { stream.Dispose(); return; } m_remoteLength = GetLength(resp); if (m_remoteLength <= 0) { stream.Dispose(); return; } m_localLength = stream.Length; SendToLua(m_localLength, m_remoteLength); if (m_localLength == m_remoteLength) { m_zipIsOk = true; m_downloadComplated = true; StartDecompress(); return; } else { stream.Close(); if (NetSpeed.GetCurrentNetType() != JzwlNetworkInfo.TYPE_MOBILE) { StartDownloadHttp(); } } }); http.DisableCache = true; http.Send(); } catch (Exception ex) { Debug.Log(ex.Message + "\n" + ex.StackTrace); } }