节点组件没有使用socket.io设置方法

时间:2015-12-29 15:57:51

标签: node.js express socket.io peerjs

我只是用socket.io配置peerjs 在this thread之后,来自服务器的组件connectdisconect之间的通信工作正常,但是当我启动socket.io集成时,会发生下一个错误:

app.set('port', port);
    ^
TypeError: Object #<Object> has no method 'set'
 This is most likely a problem with the myapp package,

我的服务器配置是:

app.set('port', (process.env.PORT || 9000));  
    app.use(express.static(__dirname + '/client'));

var peerOptions = {  
  debug: true
};

app.use('/api', expressPeerServer(server, peerOptions));

io.on('connection', function(socket){  
  socket.emit('env', process.env.NODE_ENV, app.get('port'));
});

server.listen(app.get('port'), function(){  
  console.log('Server running at localhost: ', app.get('port'));
});

App.js

var express = require('express');  
var app = express();  
var server = require('http').Server(app);  
var io = require('socket.io')(server);  
var expressPeerServer = require('peer').ExpressPeerServer;

app.set('port', (process.env.PORT || 9000));  
app.use(express.static(__dirname + '/client'));

var peerOptions = {  
  debug: true
};

app.use('/api', expressPeerServer(server, peerOptions));

io.on('connection', function(socket){  
  socket.emit('env', process.env.NODE_ENV, app.get('port'));
});

server.listen(app.get('port'), function(){  
  console.log('Server running at localhost: ', app.get('port'));
});

是否存在与我的服务器配置相关的错误?

0 个答案:

没有答案