Javascript 当使用XMLHttpRequest时,Electronjs将我的ping加倍
我正在使用Electron创建一个桌面软件。我从VPS向binance API发送了一个请求,它有320毫秒的ping。但是,当我在Electron的开发环境中发送请求时,ping加倍高达700毫秒。有人能帮我解决这个问题吗?我不知道问题出在Electron或Nodejs方面,还是因为Electron的开发环境和软件发布后,一切都会好起来?为了计算ping,我使用以下方法:Javascript 当使用XMLHttpRequest时,Electronjs将我的ping加倍,javascript,node.js,xmlhttprequest,electron,binance,Javascript,Node.js,Xmlhttprequest,Electron,Binance,我正在使用Electron创建一个桌面软件。我从VPS向binance API发送了一个请求,它有320毫秒的ping。但是,当我在Electron的开发环境中发送请求时,ping加倍高达700毫秒。有人能帮我解决这个问题吗?我不知道问题出在Electron或Nodejs方面,还是因为Electron的开发环境和软件发布后,一切都会好起来?为了计算ping,我使用以下方法: // defining a timer class Timer { constructor () {
// defining a timer
class Timer {
constructor () {
this.isRunning = false;
this.startTime = 0;
this.overallTime = 0;
}
_getTimeElapsedSinceLastStart () {
if (!this.startTime) {
return 0;
}
return Date.now() - this.startTime;
}
start () {
if (this.isRunning) {
return console.error('Timer is already running');
}
this.isRunning = true;
this.startTime = Date.now();
}
stop () {
if (!this.isRunning) {
return console.error('Timer is already stopped');
}
this.isRunning = false;
this.overallTime = this.overallTime + this._getTimeElapsedSinceLastStart();
}
reset () {
this.overallTime = 0;
if (this.isRunning) {
this.startTime = Date.now();
return;
}
this.startTime = 0;
}
getTime () {
if (!this.startTime) {
return 0;
}
if (this.isRunning) {
return this.overallTime + this._getTimeElapsedSinceLastStart();
}
return this.overallTime;
}
}
//get an instant of timer
const timer = new Timer();
timer.reset();
//send request to api
var burl = 'https://api.binance.com';
var endPoint = '/api/v3/ping';
var ourRequest = new XMLHttpRequest();
ourRequest.open('GET',burl+endPoint,true);
ourRequest.onload = function(){
timer.stop();
console.log('ping: '+timer.getTime()+' ms')
}
timer.start();
ourRequest.send();