0
我使用socket.io創建了一個簡單的聊天室。我有我的index.html這些腳本:Socket.io不能在網絡中工作
var socket = io.connect('http://imageworkz.asia:8080');
// on connection to server, ask for user's name with an anonymous callback
socket.on('connect', function(){
// call the server-side function 'adduser' and send one parameter (value of prompt)
socket.emit('adduser', prompt("What's your name?"));
});
// listener, whenever the server emits 'updatechat', this updates the chat body
socket.on('updatechat', function (username, data) {
$('#conversation').append('<b>'+username + ':</b> ' + data + '<br>');
});
// listener, whenever the server emits 'updateusers', this updates the username list
socket.on('updateusers', function(data) {
$('#users').empty();
$.each(data, function(key, value) {
$('#users').append('<div>' + key + '</div>');
});
});
// on load of page
$(function(){
// when the client clicks SEND
$('#datasend').click(function() {
var message = $('#data').val();
$('#data').val('');
// tell server to execute 'sendchat' and send along one parameter
socket.emit('sendchat', message);
});
// when the client hits ENTER on their keyboard
$('#data').keypress(function(e) {
if(e.which == 13) {
$(this).blur();
$('#datasend').focus().click();
}
});
});
當我更改爲http://localhost:8080連接,並使用「節點app.js」在控制檯命令,它工作正常啓動,但是當我把它上傳,並更改爲http://imageworkz.asia:8080,它不工作,只要我去url:http://imageworkz.asia:8080。我是否錯過了一些東西,或者還有什麼我應該做的,以使其在上傳時能夠正常工作?或者我會去錯誤的網址?謝謝!