0

我只是在这个线程之后使用socket.io配置peerjs ,组件之间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'));
});

应用程序.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'));
});

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

4

0 回答 0