2013-10-04 23 views
0

聊天並在本地主機上的工作,並沒有在Amazon EC2上的node.js +的nginx +軌聊天並在本地主機上的工作,並沒有在Amazon EC2上運行

的index.html

<html> 
<head> 
    <title> Chat with socket.io and node.js</title> 
    <style> 
    #chat { 
     height:500px; 
    } 
    </style> 
<head> 
<body> 
<h1 style="text-align:center;">CHAT</h1> 
    <div id="chat"></div> 
    <form id="send-message"> 
    <input size="35" id="message"></input> 
    <input type="submit"></input> 
    </form> 
    <script src="http://code.jquery.com/jquery-latest.min.js"></script> 
    <script src="/socket.io/socket.io.js"></script> 
    <script> 
    $(function(){ 
    var socket = io.connect(); 
    var $messageForm = $('#send-message'); 
    var $messageBox = $('#message'); 
    var $chat = $('#chat'); 

    $messageForm.submit(function(e){ 
    e.preventDefault(); 
    socket.emit('send message', $messageBox.val()); 
    $messageBox.val(''); 
    }); 

    socket.on('new message', function(data) { 
    $chat.append(data + '<br />'); 
    }); 
}); 
    </script> 
</body> 
</html> 

工作app.js

var express = require('express'), 
    app = express(), 
    server = require('http').createServer(app), 
    io = require('socket.io').listen(server); 

server.listen(3333); 

app.get('/', function(req, res){ 
    res.sendfile(__dirname + '/index.html'); 
}); 

io.sockets.on('connection', function(socket){ 
    socket.on('send message', function(data){ 
    io.sockets.emit('new message', data); 
    }); 
}); 

聊天例子是從http://www.youtube.com/watch?v=pNKNYLv2BpQ

節點-v採取v0.10.13

軌 '3.2.13'

當我運行 - >節點app.js 我得到 - >信息 - socket.io開始 &當我試圖訪問my_ip:3333 - 沒有運氣。

任何幫助或提示將非常感激。

回答

相關問題