微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用Akka手动将Pong帧发送到WebSockets

如何解决如何使用Akka手动将Pong帧发送到WebSockets

我有一个用scala-akka编写的websocket客户端,它正在消耗websocket服务器。该服务器每3分钟发送一次ping,并期待pong。乒乓消息也可以未经请求发送。

但是,akka支持自动保持活动状态,但仅在连接空闲时才支持。连接永远不会空闲,但是我想向服务器发送pong帧,否则连接将断开连接。

我试图通过这样的消息来源

val pong = Source.tick(0 minute,1 minute,BinaryMessage.apply(ByteString.apply("0xA")))
//or like this
val pong = Source.tick(0 minute,TextMessage.apply("pong"))

但是它们似乎不起作用,连接完全按照文档中的指定在3分钟后消失。

val flow = Flow.fromSinkAndSourceCoupledMat(printSink,pong)(Keep.both)
val (upgradeResponse,closed) = Http().singleWebSocketRequest(webSocketRequest,flow)

文档中提到这一点的部分:

The websocket server will send a ping frame every 3 minutes. If the websocket server does not receive a pong frame back from the connection within a 10 minute period,the connection will be disconnected. Unsolicited pong frames are allowed.

有什么建议吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。