我使用node.js和socket.io开发了一个聊天应用程序。它工作正常,直到日期,突然它开始给我错误连接丢失:服务器关闭了连接。。
Error: Connection lost: The server closed the connection.
at Protocol.end (/home/********/public_html/******/node_modules/mysql/lib/protocol/Protocol.js:109:13)
at Socket.<anonymous> (/home/******/public_html/*******/node_modules/mysql/lib/Connection.js:102:28)
at Socket.emit (events.js:117:20)
at _stream_readable.js:944:16
at process._tickCallback (node.js:458:13)
我使用的代码如下:
var app = require('express')();
app.set('port', process.env.PORT || 9000);
var server = require('http').Server(app);
var io = require('socket.io')(server);
var port = app.get('port');
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '',
database : '****'
});
console.log(port);
connection.connect();
server.listen(port, process.env.IP);
&#13;
我使用了this解决方案。但它仍然给我同样的错误。