I'm trying to get socket.io working but now in Chrome I get the error:
Uncaught ReferenceError: require is not defined
client.php:9Uncaught ReferenceError: io is not defined
I changed the way to include the socket.io.js file because it dosnt exists somewher else:
<script src="/node_modules/socket.io/lib/socket.io.js"></script>
If I try
<script src="/socket.io/socket.io.js"></script>
I get: Failed to load resource: the server responded with a status of 404 (Not Found)
This is on Ubuntu with the latest of everything
I'm using the server code from http://socket.io/ to work with in the same folder like client.php and that works, named server.js, only modified port.
If your script isn't coming from your webserver, this will not work:
<script src="/socket.io/socket.io.js"></script>
You have to explicitely state host and port:
<script src="http://localhost:<port>/socket.io/socket.io.js"></script>
Are you running node.js along PHP on your server?
There are two "socket.io" packages, a server and a client. You're trying to load the server one (/node_modules/socket.io/lib/socket.io.js
) in the browser. The script you want is called socket.io-client and you can find it at https://raw.github.com/LearnBoost/socket.io-client/master/socket.io-client.js
What happens is that socket.io automatically serves the /socket.io/socket.io.js
(the client one) file from port 80 when you're running node on port 80. In your case Apache is already at port 80, so you need to serve the file from it manually.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With