scala - how can I inject a keep-alive into a websocket handler in akka-http? -


i've written code communicate browser on websockets using akka-http 10.0.9. works nicely, except connection times out. although we're sending constant stream of data client, client isn't requesting long periods of time.

i know solution inject keep-alive messages incoming websocket source, this:

val s = source(list(data....)).keepalive(15.seconds, () => strict.textmessage("heart beat")) 

however, akka-http api calls flow handle connection:

path("query") {         parameter('session, 'package) {           (session,packageid) =>             val sg = getgraphmanager(session)             sg match {               case left(error) => complete(statuscodes.badrequest -> tserror(msg=error))               case right(gm) =>                 val tsflow = new tsflow(ksource, session)                 handlewebsocketmessages(flow.fromgraph(tsflow.flowgraph))              }          }  } 

consequently, never see incoming source, there's no opportunity inject keep-alive. how should restructure things can inject keep-alive?

the way control how connections dropped server-side change idle-timeout (see docs here , here).

you can set

idle-timeout = infinite 

to disable timeout.

if want use keep alive messages, need sent client side. .keepalive combinator easiest way them if client based on akka streams.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -