Endre - thanks alot :) On Thursday, June 9, 2016 at 3:59:06 PM UTC+5:30, Akka Team wrote: > > Hi, > > The reason why it does not keep connected is because by default all HTTP > connections have idle-timeout on by default to keep the system from leaking > connections if clients disappear without any signal. > > One way to overcome this limitation (and actually my recommended approach) > is to inject keep-alive messages on the client side (messages that the > server otherwise ignore, but informs the underlying HTTP server that the > connection is still live). > > You can override the idle-timeouts in the HTTP server configuration to a > larger value but I don't recommend that. > > If you are using stream based clients, injecting heartbeats when necessary > is as simple as calling `keepAlive` and providing it a time interval and a > factory for the message you want to inject: > http://doc.akka.io/api/akka/2.4.7/index.html#akka.stream.scaladsl.Flow@keepAlive[U > >:Out](maxIdle:scala.concurrent.duration.FiniteDuration,injectedElem:()=>U):FlowOps.this.Repr[U] > > That combinator will make sure that no periods more than T will be silent > as it will inject elements to keep this contract if necessary (and will not > inject anything if there is enough background traffic) > > -Endre > > On Thu, Jun 9, 2016 at 7:16 AM, chandra sekhar kode <[email protected] > <javascript:>> wrote: > >> I am also interested in this .. >> >> my code >> http://stackoverflow.com/questions/37716218/how-to-keep-connection-open-for-all-the-time-in-websockets >> >> >> On Wednesday, June 8, 2016 at 2:13:44 AM UTC+5:30, Marcelo Alves wrote: >>> >>> Hello, >>> I would like to configure my websocket client connection to work on >>> 2-way communication, but I have problems with that. My code : >>> >>> Sink and Source flow creation: >>> >>> def myFlow(): Flow[String, SlackMessageStreamPacket, Any] = { >>> >>> val in = Flow[String] >>> .map(SlackMessageStreamPacket(_)) >>> .to(Sink.actorRef[SlackMessageStreamPacket](actorRef, PoisonPill)) >>> >>> val out = Source.actorRef[SlackMessageStreamPacket](100, >>> OverflowStrategy.fail) >>> .mapMaterializedValue(actorRef ! Initiate2(_)) >>> >>> Flow.fromSinkAndSource(in, out) >>> } >>> >>> >>> >>> Webscoket flow creation via myFlow: >>> >>> val websocketFlow = Flow[Message].filter{ >>> case TextMessage.Strict(_) => true >>> case TextMessage.Streamed(_) => false >>> case binary: BinaryMessage => false >>> }.collect { >>> case TextMessage.Strict(msg) => msg >>> } >>> .via(myFlow) >>> .map { >>> case msg: SlackMessageStreamPacket => TextMessage.Strict(msg.message) >>> case _ => null >>> } >>> >>> >>> Connection: >>> >>> val (fut, promise) = http.singleWebSocketRequest(WebSocketRequest(uri), >>> wsFlow) >>> fut.map { >>> case v: ValidUpgrade => >>> println("connection ok!...") >>> case InvalidUpgradeResponse(response, cause) => >>> throw new RuntimeException(s"Connection to chat at $uri failed with >>> $cause") >>> } >>> >>> >>> PS.: Another way with no success : >>> >>> val websocketFlow: Flow[Message, Message, Any] = >>> Flow.fromGraph(GraphDSL.create(outputSource) { >>> implicit builder => >>> os => >>> builder.materializedValue.to(Sink.foreach(queue => actorRef ! >>> Initiate(queue))) >>> >>> val inlet = builder.add(Flow[Message].filter({ >>> case TextMessage.Strict(_) => true >>> case TextMessage.Streamed(_) => false >>> case binary: BinaryMessage => false >>> }) >>> .map({ >>> case TextMessage.Strict(text) => SlackMessageStreamPacket(text) >>> case _ => null >>> }) >>> .to(Sink.actorRef[SlackMessageStreamPacket](actorRef, >>> PoisonPill))).in >>> >>> FlowShape(inlet, os.out) >>> }) >>> >>> >>> Its connect well but not keep connected :( . Can anyone help me on that ? >>> >>> Thanks! >>> >> -- >> >>>>>>>>>> Read the docs: http://akka.io/docs/ >> >>>>>>>>>> Check the FAQ: >> http://doc.akka.io/docs/akka/current/additional/faq.html >> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user >> --- >> You received this message because you are subscribed to the Google Groups >> "Akka User List" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> Visit this group at https://groups.google.com/group/akka-user. >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Akka Team > Typesafe - Reactive apps on the JVM > Blog: letitcrash.com > Twitter: @akkateam >
-- >>>>>>>>>> Read the docs: http://akka.io/docs/ >>>>>>>>>> Check the FAQ: >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
