2016-10-10 4 views
0

나는 node.js와 socket.io에서 매우 새롭고 콘솔 (app.js 노드)에서 app.js를 실행하려고 할 때 "listening on 3000"과 색인을 입력 할 때 표시됩니다. html로 콘솔에 새로 고침하면 사용자가 here is my folder``에 연결되었다고 알려주지 않습니다. 여기 는 app.js입니다 :왜 작동하지 않습니까?

var app = require('express')(); 
var http = require('http').Server(app); 
var io = require('socket.io')(http); 

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

io.on('connection', function(socket){ 
console.log('a user connected'); 
}); 

http.listen(3000, function(){ 
console.log('listening on *:3000'); 
}); 

을 여기

 <html> 
     <head> 
     <title>Socket.IO chat</title> 
     <style> 
      * { margin: 0; padding: 0; box-sizing: border-box; } 
      body { font: 13px Helvetica, Arial; } 
      form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; } 
      form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; } 
      form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; } 
      #messages { list-style-type: none; margin: 0; padding: 0; } 
      #messages li { padding: 5px 10px; } 
      #messages li:nth-child(odd) { background: #eee; } 
     </style> 
     </head> 
     <body> 
     <ul id="messages"></ul> 
     <form action=""> 
      <input id="m" autocomplete="off" /><button>Send</button> 
     </form> 
     </body> 
    </html> 
    </html> 
</html>` 

내가 원하는 것은 콘솔에 내가 페이지를 입력 할 때 "연결된 사용자가"저를 쓸 수있는 index.htm` (이다 또는 새로 고침).

+0

(https://cdn.socket.io/socket.io-1.4 : 그래서 한 부분 "Socket.IO 통합"

링크를 읽고 계속 .5.js)를 index.html (클라이언트) 파일에 추가하십시오. –

답변

0

다음 튜토리얼을 계속 읽는다면 프론트 엔드 socket.io 라이브러리가 포함될 것입니다. 당신은 [`socket.io.js`]을 포함 할 필요가 http://socket.io/get-started/chat/