我是nodeJs.New的新手,請問一些愚蠢的問題。當在iisnode上部署nodejs webapp時,Socket get net :: ERR_CONNECTION_TIMED_OUT
我想用iisnode在Azure服務器上部署實時聊天室webapp。 webapp在localhost上運行良好,但是當我將它上載到服務器上運行時,套接字無法從客戶端連接到服務器。我正在使用nodejs + express + jade。
server.js
var express = require("express"), http = require('http');
var app = express();
var server = http.createServer(app);
var port = process.env.PORT || 3700;
app.set('views', __dirname + '/tpl');
app.set('view engine', "jade");
app.engine('jade', require('jade').__express);
var deployPath = process.env.deployPath || "";
app.get(deployPath+ "/", function(req, res){
res.render("page",{deployPath: deployPath});
});
app.use(deployPath, express.static(__dirname + '/public'));
var io = require('socket.io')(server);
server.listen(port, 'http://visafe-paltform.cloudapp.net');
io.sockets.on('connection', function (socket) {
console("connected");
socket.emit('message', { message: 'welcome to the chat' });
socket.on('send', function (data) {
io.sockets.emit('message', data);
});
});
console.log("Listening on port " + port);
Client.js
window.onload = function() {
var messages = [];
var address = window.location.protocol + '//' + window.location.host;
console.log(address);
var details = {
resource: (window.location.pathname.split('/').slice(0, -1).join('/') + '/socket.io').substring(1)
};
console.log(details);
//var socket = io.connect(address, details);
var socket = io.connect('http://visafe-paltform.cloudapp.net:3700');
//var socket = io.connect();
var field = document.getElementById("field");
var sendButton = document.getElementById("send");
var content = document.getElementById("content");
socket.on('message', function (data) {
if(data.message) {
messages.push(data.message);
var html = '';
for(var i=0; i<messages.length; i++) {
html += messages[i] + '<br />';
}
content.innerHTML = html;
} else {
console.log("There is a problem:", data);
}
});
sendButton.onclick = function() {
var text = field.value;
console.log("click:", field.value);
socket.emit('send', { message: text });
};
}
當我嘗試請求的URL,它給我的錯誤:
socket.io.js:4948 GET http://visafe-paltform.cloudapp.net:3700/socket.io/?EIO=3&transport=polling&t=LjM71Yc net::ERR_CONNECTION_TIMED_OUT
誰能幫助我?提前致謝。
@ Walter-MSFT是的它是 –
@ Walter-MSFT Windows服務器2012R –
您是否在Windows防火牆和Azure NSG上打開端口3700?根據你的錯誤日誌,似乎防火牆阻止你的服務器。 –