MySQL Forums
Forum List  »  Connector/Node.js

Extract data from TCP port
Posted by: Jothi Murugan
Date: May 08, 2019 02:14PM

Error:
/home/jothi/WorkSpaces/javaScript/Node/TCP/server/mysql/lib/protocol/Parser.js:437
throw err; // Rethrow non-MySQL errors
^

Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1970.01.01 00:001970.01.01 00:001970.01.01 00:001970.01.01 00:001970.01.01 00:00' at line 1
at Query.Sequence._packetToError (/home/jothi/WorkSpaces/javaScript/Node/TCP/server/mysql/lib/protocol/sequences/Sequence.js:47:14)
at Query.ErrorPacket (/home/jothi/WorkSpaces/javaScript/Node/TCP/server/mysql/lib/protocol/sequences/Query.js:77:18)
at Protocol._parsePacket (/home/jothi/WorkSpaces/javaScript/Node/TCP/server/mysql/lib/protocol/Protocol.js:291:23)
at Parser._parsePacket (/home/jothi/WorkSpaces/javaScript/Node/TCP/server/mysql/lib/protocol/Parser.js:433:10)
at Parser.write (/home/jothi/WorkSpaces/javaScript/Node/TCP/server/mysql/lib/protocol/Parser.js:43:10)
at Protocol.write (/home/jothi/WorkSpaces/javaScript/Node/TCP/server/mysql/lib/protocol/Protocol.js:38:16)
at Socket.<anonymous> (/home/jothi/WorkSpaces/javaScript/Node/TCP/server/mysql/lib/Connection.js:91:28)
at Socket.<anonymous> (/home/jothi/WorkSpaces/javaScript/Node/TCP/server/mysql/lib/Connection.js:525:10)
at Socket.emit (events.js:189:13)
at addChunk (_stream_readable.js:284:12)
--------------------
at Protocol._enqueue (/home/jothi/WorkSpaces/javaScript/Node/TCP/server/mysql/lib/protocol/Protocol.js:144:48)
at PoolConnection.query (/home/jothi/WorkSpaces/javaScript/Node/TCP/server/mysql/lib/Connection.js:201:25)
at /home/jothi/WorkSpaces/javaScript/Node/TCP/server/tcpmysql.js:33:11
at Handshake.onConnect (/home/jothi/WorkSpaces/javaScript/Node/TCP/server/mysql/lib/Pool.js:64:7)
at Handshake.<anonymous> (/home/jothi/WorkSpaces/javaScript/Node/TCP/server/mysql/lib/Connection.js:525:10)
at Handshake._callback (/home/jothi/WorkSpaces/javaScript/Node/TCP/server/mysql/lib/Connection.js:491:16)
at Handshake.Sequence.end (/home/jothi/WorkSpaces/javaScript/Node/TCP/server/mysql/lib/protocol/sequences/Sequence.js:83:24)
at Handshake.Sequence.OkPacket (/home/jothi/WorkSpaces/javaScript/Node/TCP/server/mysql/lib/protocol/sequences/Sequence.js:92:8)
at Protocol._parsePacket (/home/jothi/WorkSpaces/javaScript/Node/TCP/server/mysql/lib/protocol/Protocol.js:291:23)
at Parser._parsePacket (/home/jothi/WorkSpaces/javaScript/Node/TCP/server/mysql/lib/protocol/Parser.js:433:10)



Code:
var net = require("net");
var mysql = require("./mysql");

var pool = mysql.createPool({
host: "localhost",

user: "root",

password: "",

database: "mql4test"
});

var HOST = 'localhost';
var PORT = 6969;


net.createServer(function (sock){
// We have a connection - a socket object is assigned to the connection automatically
console.log('CONNECTED: ' + sock.remoteAddress + ':' + sock.remotePort);

// Identify this client
sock.name = sock.remoteAddress + ":" + sock.remotePort ;

sock.on('data', function (data) {
console.log('DATA ' + sock.remoteAddress + ': ' + data); // Write the data back to the socket, the client will receive it as data from the server

// save log to database
pool.getConnection(function (err, conn) {
if (err) throw err;
var sql = "INSERT INTO `pet` (Symbol) VALUES "+data+" ";

conn.query(sql, function (err, result) {
if (err) throw err;
});
});


let sdata = data.toString();
let d = sdata.split(',');

});

// Client closed the connection
sock.on('close', function (data) {
console.log('CLOSED: ' + sock.remoteAddress + ' ' + sock.remotePort);
});

}).listen(PORT,HOST);
// Put a friendly message on the terminal of the server.
console.log("Server running at port 6969 \ n");

Options: ReplyQuote


Subject
Written By
Posted
Extract data from TCP port
May 08, 2019 02:14PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.