When i started my socket on the npm , my Mysql conection going to down about 30 sec .I do not know why. The mysql insert method worked . But when i am waiting about 1 min -30 sec the conenction shut down.
This is error code ;
events.js:141 throw er; // Unhandled 'error' event ^
Error: Connection lost: The server closed the connection. at Protocol.end (C:\xampp\htdocs\tem\node_modules\mysql\lib\protocol\Protocol.js:109:13) at Socket. (C:\xampp\htdocs\tem\node_modules\mysql\lib\Connection.js:115:28) at emitNone (events.js:72:20) at Socket.emit (events.js:166:7) at endReadableNT (_stream_readable.js:921:12) at nextTickCallbackWith2Args (node.js:442:9) at process._tickCallback (node.js:356:17)
This is my source code;
var app = require('express')();
var mysql = require("mysql");
var http=require('http').Server(app);
var io=require('socket.io')(http);
var con = mysql.createConnection({
host: "hostname",
user: "username",
password: "pw",
database: "db"
});
con.connect(function(err){
if(err){
console.log('UnSuccesfull');
return;
}
console.log('Succesfull');
});
app.get("/",function(req,res){
res.sendfile(__dirname+"/asd.html");
});
io.on('connection',function(socket){
var UserLog={
Log:'A User Connected'
};
con.query('Insert Into Log SET ?',UserLog ,function(err){
if(err)
console.log(err);
});
});
var port=xx;
http.listen(port,'xx.xx.xx');