从这篇博客
http://gladdy.github.io/c++/2015/07/26/NodeDemystified-pt1.html 里摘一段 C++ 与 NodeJS 的对比,不知现在 V 站评论对 markdown code block 支持怎么样了,显示不好大家支看原文吧。初看一眼,卧槽, C++ 都快进化到跟人人都会写的 JS 长得一样了
```c++
TCPServer server ([&](Socket &socket) {
console.log("Client connected");
console.log("address: " + socket.remoteAddress());
console.log("port: " + socket.remotePort());
socket.on("data", [&, socket](Data data) mutable {
//Handle the received data
});
socket.on("end", [&, socket](){
//Handle the client disconnect
});
});
server.listen(1338);
```
```javascript
var server = net.createServer(function(socket){
console.log("Client connected");
console.log("address: " + socket.remoteAddress);
console.log("port: " + socket.remotePort);
socket.on("data", function(data){
//Handle client message
});
socket.on("end", function(){
//Handle client abort
});
});
server.listen(1338)
```