Как я могу интегрировать node.js и сокет IO в воспламенителе кода.
<script>
// create a new websocket
var socket = io.connect('http://localhost:8000');
// on message received we print all the data inside the #container div
socket.on('notification', function (data) {
var usersList = "<dl>";
$.each(data.users,function(index,user){
usersList += "<dt>" + user.user_name + "</dt>\n" +
"<dd>" + user.user_description + "\n" +
"<figure> <img class='img-polaroid' width='50px' src='" + user.user_img + "' /></figure>"
"</dd>";
});
usersList += "</dl>";
$('#container').html(usersList);
$('time').html('Last Update:' + data.time);
});
</script>
Как упоминается в этом вопросе SO здесь. Мой файл с именем codeigniter находится в localhost/myproject
, но nodejs прослушивает порт с помощью localhost:8000
. Итак, как я могу подключиться socket IO
. Как
var socket = io.connect('http://localhost:8000');
//here I need to make socket IO listen to localhost/myproject instead of localhost:8000 .
Как это возможно?