# Close half-open sockets

**URL:** <https://discourse.nodered.org/t/close-half-open-sockets/82254>\
**Category:** General\
**Created:** [22 October 2023 11:56 UTC](https://discourse.nodered.org/t/close-half-open-sockets/82254 "2023-10-22T11:56:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nagik](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nagik/32/83987_2.png) [@nagik](https://discourse.nodered.org/u/nagik)\
**Post date:** [22 October 2023 11:56 UTC](https://discourse.nodered.org/t/close-half-open-sockets/82254/1 "2023-10-22T11:56:15Z")

</div>

Hi,

I am fairly new to NodeRed - I would like to know how to implement the following in NodeRed:

- I am using a TCP Server to receive incoming connections from various devices.
- Since we are operating over a 'lossy network' ( cellular network) , we have implemented an  
application layer exchange of periodic 'Health check' messages to ascertain if the device is  
'online' or not.
- This is to prevent 'half-open' sockets build-up on the server side.
- If no HC messages are received from the device for a period of 1 min, we close the socket on the server side so that there is no build-up of **'half-open' sockets.**

I am trying to implement the above in NodeRed. I am using a TCPserver node for devices to connect to and receive the msg payload. However, how do I reference the socket that a specific device is connected to so that I can close it if I haven't received health check messages for some time period?

Looking forward to some help on how to about doing this in NodeRed.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [22 October 2023 12:27 UTC](https://discourse.nodered.org/t/close-half-open-sockets/82254/2 "2023-10-22T12:27:15Z")

</div>

My advice would be use a protocol designed for "poor" networks. If you can, use MQTT and forget about all the packet parsing, half close/hung sockets etc. MQTT just does its thing.

If not then you might have to code it all yourself in a function node by importing a socket library like node:net

---

<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:** [21 December 2023 12:28 UTC](https://discourse.nodered.org/t/close-half-open-sockets/82254/3 "2023-12-21T12:28:05Z")

</div>

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