कनेक्ट करें मैं नोड और माइस्क्ल के साथ काम करने की कोशिश कर रहा हूं लेकिन डेटाबेस से कनेक्ट करने का प्रयास करते समय मुझे त्रुटि का सामना करना पड़ता है।त्रुटि: ETIMEDOUT
//For mysql server
var mysql = require('mysql');
var connection = mysql.createConnection(
{
host: 'example.com',
user: 'abc',
password: '***',
database: 'abcd',
port: 3306,
});
// If there is an error connecting to the database
connection.connect(function(err)
{
if (err)
{
throw err;
}
else
{
console.log('DB connection establish');
}
});
function check_userid(usersId)
{
var que = connection.query(
'select * from table where id = '+usersId, function(err, result, fields){
if(err) throw err;
console.log('Resultset: ', result);
console.log('Length of Resultset: ', result.length);
if(result.length == 0)
{
connection.query('insert into table (id, user_status) values ("' + usersId + '", "' + 'connected' + '")',
function (err, result)
{
if (err) throw err;
console.log('Updation of table: ',result.insertId);
});
}
else
{
connection.query('update table SET user_status="'+'connected'+'" WHERE id = "' + usersId + '"',
function (err, result)
{
if (err) throw err;
console.log('Updation of Table: ',result.insertId);
});
}
});
}
//For websocket
var webSocketServer = new (require('ws')).Server({port: (process.env.PORT || 5000)}),
webSockets = {} // userID: webSocket
// CONNECT /:userID
// wscat -c ws://localhost:5000/1
webSocketServer.on('connection', function (webSocket)
{
var userID = parseInt(webSocket.upgradeReq.url.substr(1), 10)
webSockets[userID] = webSocket
console.log('connected: ' + userID + ' in ' + Object.getOwnPropertyNames(webSockets))
check_userid(userID);
// Forward Message
//
// Receive Example
// [toUserID, text] [2, "Hello, World!"]
//
// Send Example
// [fromUserID, text] [1, "Hello, World!"]
webSocket.on('message', function(message) {
console.log('received from ' + userID + ': ' + message)
var messageArray = JSON.parse(message)
var toUserWebSocket = webSockets[messageArray[0]]
if (toUserWebSocket) {
console.log('sent to ' + messageArray[0] + ': ' + JSON.stringify(messageArray))
messageArray[0] = userID
toUserWebSocket.send(JSON.stringify(messageArray))
}
})
webSocket.on('close', function() {
delete webSockets[userID]
console.log('deleted: ' + userID)
connection.query('update table SET user_status="'+'disconnected'+'" WHERE id = "' + userID + '"',
function (err, result)
{
if (err) throw err;
console.log('Updation of table: ',result.insertId);
});
})
})
और मैं हो रही निम्नलिखित त्रुटि रखने
Error: connect ETIMEDOUT
at errnoException (net.js:904:11)
at Object.afterConnect as oncomplete
--------------------
at Handshake.Sequence (/Users/apple/Desktop/js/node_modules/mysql/lib/protocol/sequences/Sequence.js:15:21)
at new Handshake (/Users/apple/Desktop/js/node_modules/mysql/lib/protocol/sequences/Handshake.js:9:12)
at Protocol.handshake (/Users/apple/Desktop/js/node_modules/mysql/lib/protocol/Protocol.js:44:50)
at Connection.connect (/Users/apple/Desktop/js/node_modules/mysql/lib/Connection.js:38:18)
at Object. (/Users/apple/Desktop/js/server.js:13:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
विवरण: मैं स्थानीय होस्ट में एक ही सर्वर चलाने के लिए, और सफलतापूर्वक phpMyAdmin साथ जुड़ा हुआ है और मुझे लगता है कि त्रुटि नहीं मिला था, लेकिन जब मैं में है कि सर्वर को लागू वीपीएस यह phpMyadmin के साथ कनेक्शन नहीं बना सकता है और कहें ETIMEDOUT कनेक्ट करें।
(stackoverflow.com/users/2050455/mscdex): मैं उस मशीन को स्थानीय मशीन (xamp का उपयोग करके) चला रहा था, यह सफलतापूर्वक phpMyadmin से जुड़ा हुआ था। उस चल रहे सर्वर का उपयोग करते समय, जब क्लाइंट सर्वर से कनेक्ट होता है, सर्वर क्वेरी का उपयोग करके phpMyadmin तालिका में सफलतापूर्वक विवरण दर्ज करता है। लेकिन जब मैं उस सर्वर को वीपीएस पर चलाता हूं, तो यह phpMyadmin (i.e mysql.transip.nl) से कनेक्ट नहीं हो सकता है और 2min के बाद मुझे त्रुटि मिली। क्या आप मेरे प्रश्न को फिर से जांच सकते हैं क्योंकि मैं अपने प्रश्न में संपादित करता हूं? –