Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
計網概
// net 模組
var net = require('net');
// 建立一個 TCP 伺服器,當有人建立連線時就 ...
var server = net.Server(function (socket) { // 連線會當參數傳進來
// 當有資料從這連線傳過來時就 ...
socket.on('data', function (data) { // 資料會當參數傳進來
// 輸出到 console
console.log(data.toString()); // 位元組轉字串給人類看
});
}).listen(1337) // 監聽 port 1337
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment