So I'm trying to test out my socket.io website and on the website I have
<script type="text/javascript" src="http://localhost:82/socket.io/socket.io.js"></script>
....
var socket = io.connect('http://localhost:82');
just like on the socket.io example. This works fine when I test on my localhost machine, but when I use another machine on开发者_开发知识库 the same network, I can only get to the website, but socket won't connect. What am I doing wrong?
I am assuming that
<script type="text/javascript" src="http://localhost:82/socket.io/socket.io.js"></script>
should be
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
but that doesn't work an the browser assumes that I want to retrieve that .js file page from the website rather than what it's supposed to do. Why does
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
not work on my website (xampp/codeigniter) when it's in the socket.io example client?
Are you using XAMPP? You need to allow access remotely - new xammpp security concept
Anyway, I am doing something similar and this works for me - just change from localhost to the ip address of the machine running the web server.
<script type="text/javascript" src="192.168.1.23:8080/socket.io/socket.io.js"></script>
this.socket = new io.connect('192.168.1.23:8080');
精彩评论