lundi 29 mars 2021

initialize client socket in node file that will be sent

I send information to clients from a nodejs server like this :

app.get([...]
    let index = await readFileAsync(path.join(__dirname, 'file.js'), 'utf8');
    res.send(index);
)

I want to initialise a socket in my file.js.

In the socket io documentation, you can do this:

<script src="/socket.io/socket.io.js"></script>
<script>
  var socket = io();
</script>

So I try to copy/paste socket.io.js directly in my file.js and add var socket = io(); at the end, but I got this error on my client : GET http://127.0.0.1:5500/socket.io/?EIO=4&transport=polling&t=NXz6N1S 404 (Not Found)

There is a way to initialize my client socket in the file.js?




Aucun commentaire:

Enregistrer un commentaire