I was trying to program a system that calculates the CPU speed with javascript but I keep on running into socket script source not defined and io is not defined on my console the exact error is /socket.io/socket.io.js ERR_ABORTED 404 (Not Found)
. Do you have any idea what might be causing this issue? I double-checked if the src for socket changed at their documentation but no I have the right src I have also tried using <script src="https://cdn.socket.io/3.1.3/socket.io.min.js" integrity="sha384-cPwlPLvBTa3sKAgddT6krw0cJat7egBga3DJepJyrLl4Q9/5WLra3rrnMcyTyOnh" crossorigin="anonymous"></script>
instead but that did not solve the issue. Both my HTML and javascript code are attached below. Thanks in advance.
Html
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io();
</script>
Javascript
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var os = require('os-utils');
app.use(express.static('temp.html'));
var cpuHistogram = [];
var histogramLengtn = 61;
var interval = 100;
http.listen(80, function() {
console.log('listening on localhost')
for(var i = 0; 1 < histogramLenth; i++){
cpuHistogram[i] = [i, 0];
}
setInterval(function() {
os.cpuUsage(function(value){
io.emit('cpu histogram', value);
});
}, interval);
});
declare io like below
var io = require("socket.io").listen(server);
try something like these if you use nginx
location /socket.io/ {
proxy_pass https://{ip}:{port};
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.