mirror of
https://github.com/2dust/v2rayN.git
synced 2025-05-11 18:58:20 +00:00
Update SpeedtestService.cs
This commit is contained in:
parent
3bc79a4ba1
commit
aa133bb50b
1 changed files with 3 additions and 5 deletions
|
@ -336,21 +336,19 @@ namespace ServiceLib.Services
|
||||||
ipAddress = ipHostInfo.AddressList.First();
|
ipAddress = ipHostInfo.AddressList.First();
|
||||||
}
|
}
|
||||||
|
|
||||||
var timer = Stopwatch.StartNew();
|
|
||||||
|
|
||||||
IPEndPoint endPoint = new(ipAddress, port);
|
IPEndPoint endPoint = new(ipAddress, port);
|
||||||
using Socket clientSocket = new(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
using Socket clientSocket = new(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
||||||
|
|
||||||
|
var timer = Stopwatch.StartNew();
|
||||||
var result = clientSocket.BeginConnect(endPoint, null, null);
|
var result = clientSocket.BeginConnect(endPoint, null, null);
|
||||||
if (!result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(5)))
|
if (!result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(5)))
|
||||||
{
|
{
|
||||||
throw new TimeoutException("connect timeout (5s): " + url);
|
throw new TimeoutException("connect timeout (5s): " + url);
|
||||||
}
|
}
|
||||||
|
|
||||||
clientSocket.EndConnect(result);
|
|
||||||
|
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
responseTime = (int)timer.Elapsed.TotalMilliseconds;
|
responseTime = (int)timer.Elapsed.TotalMilliseconds;
|
||||||
|
|
||||||
|
clientSocket.EndConnect(result);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue