【发布时间】:2015-12-17 08:56:27
【问题描述】:
我有一个我需要修改的 TCP 服务器,它只接受来自预定义 IP 的请求。我的想法是创建一个数组,包含所有允许的 IP,但是如何进行检查以及如何围绕我现有的代码进行检查?
代码:
// Load the TCP Library
var net = require('net')
// Start a TCP Server
net.createServer(function (socket) {
socket.setKeepAlive(true)
// TODO: Add mysql connection list entry
console.log('connected', socket.remoteAddress)
socket.on('close', function(err){
if (err) throw err;
// TODO: Add mysql connection list entry
console.log('disconnected', socket.remoteAddress)
})
}).listen(5000);
// Put a friendly message on the terminal of the server.
console.log("Server running at port 5000");
【问题讨论】: