I followed this content for data communication and packet capturing(syn, syn-ack, ack..). https://dev.to/kalpitrathore/various-ways-of-real-time-data-communication-in-node-js-1h2b
I used VMware, Kali linux and firefox broweser.
I copied the code and followed the step, and I got this problem, and I couldn't find a way to fix it. Please help!
Content Security Policy: The page’s settings blocked the loading of a resource at http://localhost:7777/favicon.ico (“default-src”).
++ Here are codes
app.js
const http = require('http')
const express = require('express')
const WebSocket = require('ws')
const app = express()
const port = 80
app.use('/', express.static('public'));
const server = http.createServer(app);
const wss = new WebSocket.Server({ server })
var data = "Real-Time Update 1";
var number = 1;
wss.on('connection', ws => {
ws.on('message', message => {
console.log(`Received message => ${message}`)
})
var interval = setInterval(function(){
data = "Real-Time Update "+number;
console.log("SENT: "+data);
ws.send(data)
number++;
}, randomInteger(2,9)*1000);
ws.on('close', function close() {
clearInterval(interval);
});
})
function randomInteger(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
server.listen(port, () => {
console.log(`Listening at http://localhost:${port}`)
})
index.html
<head>
<title>Server Sent Events</title>
</head>
<body>
<div id="updates"></div>
</body>
<script type="text/javascript">
const connection = new WebSocket('ws://localhost:80')
connection.onmessage = e => {
document.getElementById('updates').innerHTML = document.getElementById('updates').innerHTML + "Received: "+e.data+"</br>";
}
</script>