trying to import socket.io in html #4604
-
Hello, I'm learning about socket.io, looking at the docs I saw that I could import socket.io in html but unfortunately I couldn't. the socket server is ok. <!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Chat socket.io</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.5.4/socket.io.js" integrity="sha512-YeeA/Qxn5hYdkukScTCNNOhTrv1C2RubAGButJ1rmgQwZf/HdRaCGl+JAVkqsqaNRaYNHdheiuKKuPf9mDcqKg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.5.4/socket.io.min.js" integrity="sha512-HTENHrkQ/P0NGDFd5nk6ibVtCkcM7jhr2c7GyvXp5O+4X6O5cQO9AhqFzM+MdeBivsX7Hoys2J7pp2wdgMpCvw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</head>
<body>
</body>
<script type="text/javascript" charset="utf-8">
const socket = io("http://0.0.0.0:8080");
</script>
</html> |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
Hi Sebastian, In your browser's console, what error is displayed? <!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Chat socket.io</title>
<script src="http://localhost:8080/socket.io.js"></script>
</head>
<body>
</body>
<script type="text/javascript" charset="utf-8">
const socket = io("http://0.0.0.0:8080");
</script>
</html> |
Beta Was this translation helpful? Give feedback.
-
It looks like your script not your server is not generating the JS. If you access http://localhost:8080/socket.io.js in the browser, does it show anything? If you run the script I gave you, |
Beta Was this translation helpful? Give feedback.
-
I was trying to import the socket.io in the html but it was giving an error (io not defined) and with these scripts I managed to solve my error. I thank @El-Tommy for his attention and for having tried to help me this time. <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.5.4/socket.io.js" integrity="sha512-YeeA/Qxn5hYdkukScTCNNOhTrv1C2RubAGButJ1rmgQwZf/HdRaCGl+JAVkqsqaNRaYNHdheiuKKuPf9mDcqKg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.5.4/socket.io.min.js" integrity="sha512-HTENHrkQ/P0NGDFd5nk6ibVtCkcM7jhr2c7GyvXp5O+4X6O5cQO9AhqFzM+MdeBivsX7Hoys2J7pp2wdgMpCvw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
const socket = io("ws://address")
</script> |
Beta Was this translation helpful? Give feedback.
I was trying to import the socket.io in the html but it was giving an error (io not defined) and with these scripts I managed to solve my error. I thank @El-Tommy for his attention and for having tried to help me this time.