将节点 js 和套接字 IO 与 codeigniter 集成
2022-08-30 23:43:44
如何在代码点火器中集成节点.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 的我的视图文件在,但 nodejs 使用 侦听 port。那么我该如何连接.喜欢localhost/myproject
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 .
这怎么可能?