Jak mogę zintegrować node.js i IO gniazda w kreatorze kodu.Integracja węzła js i gniazda IO z podpisem kodu
<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>
Jak wspomniano w tym pytaniu dotyczącym SO here. Mój plik widoku z codeigniter jest w localhost/myproject
, ale nodejs słucha portu przy użyciu localhost:8000
. Jak więc podłączyć socket IO
. Podobnie jak
var socket = io.connect('http://localhost:8000');
//here I need to make socket IO listen to localhost/myproject instead of localhost:8000 .
Jak to jest możliwe?
ścieżka jest ignorowana przez serwer gniazd, chyba że używa go do konfiguracji jakoś, które gniazdo. io nie. – dandavis
Nie mogę zrozumieć, co mówisz. Czy mógłbyś to dokładniej wyjaśnić? – user254153
Spójrz na ten moduł, 'https: // github.com/nodejitsu/node-http-proxy' –