CharchitSaraswat
How to create a keep-alive API endpoint with Cowboy
Note: I am new to elixir and the forum, and hence my question might be missing some details. Do let me know if additional information is required from my end.
I am trying to integrate the trading view’s /streaming endpoint.
A snippet of what it says is:
Stream of prices. Server constantly keeps the connection alive. If the connection is broken - the server constantly tries to restore it. TradingView establishes up to 4 simultaneous connections to this endpoint and expects to get the same data to all of them. Transfer mode is chunked encoding . The data feed should set 'Transfer-Encoding: chunked' and make sure that all intermediate proxies are set to use this mode. All messages are to be ended with \n . Data stream should contain real-time data only. It shouldn’t contain snapshots of data.
Can anyone help me implement an endpoint that can keep the connection alive? I am using cowboy as the framework.
I have already used Plug’s send_response and send_chunked in conjunction with halt, but it did not work out.
First Post!
03juan
Welcome to the forum! Hope you find your time here and with Elixir rewarding and fun.
Plug.Cowboy - Options docs say that
All other options given at the top level must configure the underlying socket. For HTTP connections, those options are listed under
ranch_tcp. For example, you can set:ipv6_v6onlyto true if you want to bind only on IPv6 addresses.
So you can try setting keepalive: true wherever you are configuring that connection.







