내가 이해 한대로 http://socket.io/#how-to-use에서 node.js는 자동으로 서버의 socket.io 파일을 제공합니다.Node.js 서버에서 Socket.io가 제공되지 않습니다
npm install socket.io
과 함께 socket.io를 설치했으며 서버 루트의 한 수준 위의 node_modules
에 있음을 알 수 있습니다.
server.js :
var static = require('./plugins/node-static');
var socketIO = require('socket.io');
var clientFiles = new static.Server('./client');
var http = require('http');
httpServer = http.createServer(function (request, response) {
request.addListener('end', function() {
clientFiles.serve(request, response);
});
}).listen(8253);
var webSocket = socketIO.listen(httpServer);
webSocket.on('connection', function(client) { .....
index.html을 :
<html>
<head>
<title>Chat</title>
</head>
<body>
<script src="/socket.io/socket.io.js"></script>
<script type="text/javascript"
src="http://code.jquery.com/jquery-1.5.2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var webSocket = new io.Socket('localhost', { port: 8253 });
webSocket.connect(); .......
서버가 잘 작동 시작하지만, index.html을을 열 때, 나는 다음과 같은 오류가 나타납니다
GET http://localhost:8253/socket.io/socket.io.js 404 (Not Found)
Uncaught ReferenceError: io is not defined :8253/:25
을
아이디어?
"서버 루트의 한 수준 위의 node_modules에 있습니다." "서버 루트"는 무엇을 의미합니까? 아마 아파치의 흔적과 혼동하지 않을까요? NPM에 의해 설치된 모듈은 NPM repos에 있으며, 프로젝트의 주 노드 스크립트와 관련이있는 것은 아닙니다. 성공적인'require ('socket.io')'는 설치가 정상이고 문제가 코드에 있음을 나타냅니다. – Kos