I have a LAMP server where I'm running apache and server.js, I also have an index.html:
<html>
<head>
<script src="/socket.io/socket.io.js"></script>
</head>
<body>
<script>
var socket = io();
</script>
</body>
<style>
html, body {
padding: 0px;
margin: 0px;
color: #FFF;
background-color: #333;
}
</style>
</html>
In the console, I'm getting the error:
http://localhost/socket.io/?EIO=3&transport=polling&t=LJ0ESOW Failed to load resource: the server responded with a status of 404 (Not Found)
I'm using npm install socket.io to install Socket.io for the server (node), and npm install Socket.io-client for the client which I should be able to run in my normal java script browser!
What's the issue? Am I installing wrong?
If your socket.io
server is listening on localhost:8000
, you need to retrieve the client code from there:
<script src="http://localhost:8000/socket.io/socket.io.js"></script>
Otherwise, the client is being requested from Apache, which doesn't have the correct handler for that URL.
The client should also be pointed to the correct server location:
var socket = io('http://localhost:8000');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.