# How to deny a tcp connection

**URL:** https://discourse.nodered.org/t/how-to-deny-a-tcp-connection/55756
**Category:** General
**Created:** [27 December 2021 16:22 UTC](https://discourse.nodered.org/t/how-to-deny-a-tcp-connection/55756 "2021-12-27T16:22:34Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![alexander77](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@alexander77](https://discourse.nodered.org/u/alexander77)
#### Post date: [27 December 2021 16:22 UTC](https://discourse.nodered.org/t/how-to-deny-a-tcp-connection/55756/1 "2021-12-27T16:22:34Z")

</div>

I have written a small, specialized version of a "MQTT Server". The only thing it can is to distribute logic states and numbers to all connected systems.  
The UI lets you declare, which ip-addresses are allowed (and by that which are not allowed).  
I have limited the number of cennoctions - well not really - to 12 known addresses, only messages from these devices will be distributed to all open connections.  
The problem is: the tcp server acceps all connections, i need to filter the unwanted devices, but the unwanted connection could be still alive.  
My question is: how can i close a connection from a device that is not in my list?

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [27 December 2021 16:39 UTC](https://discourse.nodered.org/t/how-to-deny-a-tcp-connection/55756/2 "2021-12-27T16:39:27Z")

</div>

If you are using your own node.js tcp code you can use socket.destroy() to terminate the connection.

---

<div class="post-metadata">

### Author: ![alexander77](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@alexander77](https://discourse.nodered.org/u/alexander77)
#### Post date: [27 December 2021 17:01 UTC](https://discourse.nodered.org/t/how-to-deny-a-tcp-connection/55756/3 "2021-12-27T17:01:29Z")

</div>

My own node.js tcp code ???  
No, i use the node-red tcp in and tcp out node.  
I will look what i can find about node.js tcp code.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [27 December 2021 19:04 UTC](https://discourse.nodered.org/t/how-to-deny-a-tcp-connection/55756/4 "2021-12-27T19:04:06Z")

</div>

sorry - when you said you had written a small specialised version I assumed you were creating your own node. So yes - the existing TCP nodes do not allow you to force a disconnection.

---

<div class="post-metadata">

### Author: ![alexander77](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@alexander77](https://discourse.nodered.org/u/alexander77)
#### Post date: [27 December 2021 19:45 UTC](https://discourse.nodered.org/t/how-to-deny-a-tcp-connection/55756/5 "2021-12-27T19:45:42Z")

</div>

Thank you for the answer, i love clear statements ( even if the content is a little bit disappointing ... ).  
Where could i find a sample of creating it with nodejs? I found some very simple code examples, but i would not know how to integrate it in node-red.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [10 January 2022 19:46 UTC](https://discourse.nodered.org/t/how-to-deny-a-tcp-connection/55756/6 "2022-01-10T19:46:14Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
