Reputation: 1479
I have nodeJs application which is running on server http://mysite.co:8081
. Where I have chat application. Using socket.io
for communication.
Now I want to connect to socket
from localhost
-- I am trying to connect from my machine where I have wamp installed and in that created one html
file in www/test/index.html
.
The index.html
have below code only.
<script src="http://mysite.co:8081/socket.io/socket.io.js"></script>
<script>
var socket = io('http://mysite.co:8081');
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
</script>
The socket.io.js
file is loading correctly, But I am getting below error
Uncaught TypeError: io is not a function
Let me now what I am doing wrong.
Thanks,
Upvotes: 0
Views: 2989
Reputation: 1465
try this one:
<script src="http://mysite.co:8081/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://mysite.co:8081');
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
</script>
Upvotes: 1