Is the tcp sensor not accepting data? I try to use it but the connection is lost

Hello everyone

This is the configuration in HomeAssistant

sensor:
  - platform: tcp
    host: 192.168.99.122
    port: 6638
    payload: "1"

Even without any receiving data
tcp sensor loses connection at certain time intervals
This is the log of the server (esp32) when it lost the connection

[23:02:35][D][stream_server:081]: New client connected from 192.168.99.122
[23:02:35][D][uart_debug:114]: >>> 31
[23:02:45][D][stream_server:163]: Client 192.168.99.122 disconnected
[23:03:05][D][stream_server:081]: New client connected from 192.168.99.122
[23:03:05][D][uart_debug:114]: >>> 31
[23:03:15][D][stream_server:163]: Client 192.168.99.122 disconnected

This server is esp32 and uses the external component Stream server for ESPHome.
This is the link GitHub - oxan/esphome-stream-server: Stream server (serial-to-wifi bridge) for ESPHome

my goal is
Let the tcp sensor change state when receiving data
Then let the automation use this state
I don’t know if this method is correct
Maybe this tcp sensor is not used this way?