But the recent hot server side JS really because of the Node.js project. Douglas Crockford (Yahoo!) also has a topic "comeback: Server-side JavaScript" mentioned node.js at Velocity's 2010 convention. For more information on Node.js, please google.
A very large feature of Node.js is event-driven, which is very handy when developing server-side services. Last night, Sina's @timyang also mentioned Node.js, and Sina Weibo is expected to notice its merits. At the same time, Taobao recently also expressed a considerable interest in node.js. See also: http://www.tbdata.org/archives/1285 http://www.tbdata.org/archives/1292, in order to experience one, wrote a transparent proxy service layer with Node.js, the code is as follows:
Copy Code code as follows:
var net = require (' net ');
var proxyhost= "127.0.0.1";/IP of the proxy service
var proxyport=3306;//the proxy port
var listenport=8124;//proxy Port
Net.createserver (function (socket) {
Socket.on ("Connect", function () {
Console.log (' connected ');
try{
var db=net.createconnection (proxyport,proxyhost);
Db.on ("Connect", function () {
Console.log ("Server Connected");
Socket.on ("Data", function (data) {
Db.write (data);
});
Db.on ("Data", function (data) {
Console.log (data.tostring (' UTF8 ', 0,data.legnth));
Console.log (data);
Socket.write (data);
});
Socket.on ("Close", function () {
Console.log ("server closed");
Db.destroy ();
});
});
Db.on ("Error", function (data) {
Console.log ("error:\r\n" +data);
});
Db.on ("End", function () {
Console.log ("server closed");
Socket.destroy ();
});
}catch (Err) {
Console.log (ERR);
}
});
}). Listen (Listenport, "0.0.0.0");
For testing, the production environment needs to consider stability code processing
OK, it's done, just a little bit of time, yes, it's that simple. We put the proxyhost,proxyport=3306 to change the cost of a data on the machine, after starting, I use the MySQL client even 8124, you can connect to the 3306-port database.
Not only the database, the Proxyhost,proxyport point to memcached, then become memcached agent.
By Console.log you can easily debug the protocol. It can also be used to monitor some protocols that are not open.
Using Node.js to develop network service applications, such as the agent layer, httpserver processing is very convenient.
A friend has just come up with a bug, thanks to this friend.