Reputation: 49
I'm trying to identify the clients when they try to connect to my tcp server so i can reject or accept the connection.But I find it hard to find the answers to my problem or if it even possible to achieve this before allowing the client to connect first.
I have an idea. If the clients connects to: tcp://127.0.0.1:8080?auth=34356
we can check the auth parameter to identify the clients. The problem i don't know how to achieve this.
I'm using nodejs as tcp server like this:
var netlib = require('net');
var server = netlib.createServer(function(socket) {
});
server.on('connection', function (socket) {
console.log('CONNECTED SOCKET DATA', socket.address());
console.log('CONNECTED LOCAL, %s:%s', socket.localAddress, socket.localPort);
console.log('CONNECTED %s:%s', socket.remoteAddress, socket.remotePort);
});
server.listen(8080, '127.0.0.1');
Can someone please show me how to get the url parameter and value?
Upvotes: 1
Views: 1115
Reputation: 249592
TCP doesn't have a concept of authentication during connection establishment. You'll need to decide on a protocol which will probably be used for the entire session. Once you decide on such a protocol, the client will simply send its authentication data as the first message. If the server doesn't receive valid authentication data, it will close the connection.
Upvotes: 1