V
V
Vladimir2019-04-25 06:20:37
Node.js
Vladimir, 2019-04-25 06:20:37

How to deny access to a server or its room to a specific socket.io client?

I caught socket.id, but it is always different, it can only be used to prohibit a one-time entry, but how to prohibit entry forever?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir, 2019-04-25
@HistoryART

Here is the answer, here we get the ip on the client and pass it to the server:

$.getJSON('https://api.ipify.org?format=json', function(data){ 
  	socket.emit('banned',data.ip); 
});

On the server we accept and filter:
socket.on('banned', function(data) {
   		var ban = 'user.ip';
   		if(data == ban) {
   			io.emit('ban', 'Вы забанены!');
   			socket.disconnect(true);
   		}
   	});

A
Alexander, 2019-04-25
@NeiroNx

First you need to understand - how to determine the client that he is the one who should be banned. And only then at the moment of definition and prohibit.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question