Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js+;socket.io+;apachelinux服务器上的express框架_Node.js_Linux_Apache_Sockets_Real Time - Fatal编程技术网

Node.js+;socket.io+;apachelinux服务器上的express框架

Node.js+;socket.io+;apachelinux服务器上的express框架,node.js,linux,apache,sockets,real-time,Node.js,Linux,Apache,Sockets,Real Time,我对node.js交互是新手。 但是我已经在我的服务器上安装了node.js,并在我的服务器的特定域上安装了所有必要的node\u模块 我构建了一个服务器index.js文件、一个index.html和一个package.json(都位于httpdocs) index.js var app = require('express')(); var http = require('http').Server(app); var io = require('socket.io')(http); ap

我对
node.js
交互是新手。 但是我已经在我的服务器上安装了
node.js
,并在我的服务器的特定域上安装了所有必要的
node\u模块

我构建了一个服务器
index.js
文件、一个
index.html
和一个
package.json
(都位于
httpdocs

index.js

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

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

io.on('connection', function(socket){
  console.log('a user connected');
 io.emit('chat message', "Someone connected");

  socket.on('disconnect', function(){
    console.log('user disconnected');
   io.emit('chat message', "Someone has disconnect");
 });

 socket.on('chat message', function(msg){
  console.log('message: ' + msg);
  io.emit('chat message', msg);
   });
 });

http.listen(80, function(){
  console.log('listening on *:80');
});
客户端脚本(在index.html中)

当我提交表单时,消息显示正确。但是
index.js
文件似乎根本不起作用


请告诉我哪里出了问题以及如何解决。

您必须修改apache服务器提供的文件。我不记得它确切的位置,但您必须(至少)从该列表中排除index.html。更常见的方法是-nginx,您必须修改apache服务器提供的文件。我不记得它确切的位置,但您必须(至少)从该列表中排除index.html。更常见的方法是-nginx。
<script src="/socket.io/socket.io.js"></script>
<script src="https://code.jquery.com/jquery-1.11.1.js"></script>
<script>
 var socket = io();
 $('form').submit(function(){
   socket.emit('chat message', $('#m').val());
  $('#m').val('');
   return false;
 });
 socket.on('chat message', function(msg){
   $('#messages').append($('<li>').text(msg));
});
{
"name": "App",
"version": "0.0.1",
"description": "App",
"scripts": {
"start": "node ./index.js"
},
 "dependencies": {
    "socket.io": "latest",
    "express": "latest"
 },
 "author": "developer"
 }