0

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>
Chol
  • 15
  • 1
  • 6
  • Please post relevant details in the question. Your link can go stale – mplungjan Apr 27 '23 at 05:28
  • Does this answer your question? [How does Content Security Policy (CSP) work?](https://stackoverflow.com/questions/30280370/how-does-content-security-policy-csp-work) – Ron Apr 27 '23 at 08:53

0 Answers0