# TCP input and answer to client

**URL:** <https://discuss.elastic.co/t/tcp-input-and-answer-to-client/324338>\
**Category:** Logstash\
**Created:** [January 31, 2023, 1:44pm UTC](https://discuss.elastic.co/t/tcp-input-and-answer-to-client/324338 "2023-01-31T13:44:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![M\_K1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/m_k1/32/116602_2.png) [@M\_K1](https://discuss.elastic.co/u/M_K1)\
**Post date:** [January 31, 2023, 1:44pm UTC](https://discuss.elastic.co/t/tcp-input-and-answer-to-client/324338/1 "2023-01-31T13:44:41Z")

</div>

Hello!  
is it possible to do in logstash? i need to receive strings throuth tcp input and after succssesful recievment i need to answer the client with string for example "ok" or "bad format"

---

<div class="post-metadata">

**Author:** ![Rios](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rios/32/95745_2.png) [@Rios](https://discuss.elastic.co/u/Rios)\
**Post date:** [January 31, 2023, 2:04pm UTC](https://discuss.elastic.co/t/tcp-input-and-answer-to-client/324338/2 "2023-01-31T14:04:01Z")

</div>

Should be something like this

```auto
input {
        tcp {
                type => "syslog"
                port => 514 # default port
        } 
}
filter {
  if [message] == "somestring" { # you can use IN or Regex
    mutate { add_field => { "status" => "OK"} }	
    prune { whitelist_names => ["status"] }
  }
}
output {
  tcp {
    host => "host or ip"
    port => 514
  }
    stdout { codec => rubydebug{} }
}

```

---

<div class="post-metadata">

**Author:** ![M\_K1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/m_k1/32/116602_2.png) [@M\_K1](https://discuss.elastic.co/u/M_K1)\
**Post date:** [January 31, 2023, 2:19pm UTC](https://discuss.elastic.co/t/tcp-input-and-answer-to-client/324338/3 "2023-01-31T14:19:12Z")

</div>

Thanks.  
But I need to answer the current client in the current tcp session.  
tcp output will create a new connection to host and host must be as a server.

---

<div class="post-metadata">

**Author:** ![Rios](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rios/32/95745_2.png) [@Rios](https://discuss.elastic.co/u/Rios)\
**Post date:** [January 31, 2023, 2:56pm UTC](https://discuss.elastic.co/t/tcp-input-and-answer-to-client/324338/4 "2023-01-31T14:56:14Z")

</div>

Try with adding `tcp_keep_alive => true`  
If not work, maybe ES ingest pipeline can help.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [January 31, 2023, 6:01pm UTC](https://discuss.elastic.co/t/tcp-input-and-answer-to-client/324338/5 "2023-01-31T18:01:22Z")

</div>

> [@M\_K1](#):
>
> i need to receive strings throuth tcp input and after succssesful recievment i need to answer the client with string for example "ok" or "bad format"

logstash is not a web server, it provides no way to respond to a client sending data.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 28, 2023, 6:01pm UTC](https://discuss.elastic.co/t/tcp-input-and-answer-to-client/324338/6 "2023-02-28T18:01:35Z")

</div>

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