Getting error while using socket.io in html tag

352 views Asked by At

I am learning socket.io from their documentation but I can not solve this error, which I guess appearing due to using the script tag before body end.

This is the image showing the tag I am getting error and here you can also understand my directory structure: Image

Thanks in advance, I have tried all earlier solutions I have found on StackOverflow

1

There are 1 answers

1
Sandeep Ranjan On

The solution is that you need to copy socket.io.js to a public folder (something as resources/js/socket.io.js). This is not the preferred way.

Instead, if your Socket.io server listens properly to your HTTP server, it will automatically serve the client file via http://localhost:<port>/socket.io/socket.io.js, now you don't need to find socket client js file or copy in a public folder as resources/js/socket.io.js & serve it manually.

If still facing an issue then use the following CDN link Read here for more info

<script src="https://cdn.socket.io/3.1.1/socket.io.min.js" integrity="sha384-gDaozqUvc4HTgo8iZjwth73C6dDDeOJsAgpxBcMpZYztUfjHXpzrpdrHRdVp8ySO" crossorigin="anonymous"></script>