Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 如何从Akka Http Web套接字客户端接收消息?_Scala_Akka_Akka Stream_Akka Http_Java Websocket - Fatal编程技术网

Scala 如何从Akka Http Web套接字客户端接收消息?

Scala 如何从Akka Http Web套接字客户端接收消息?,scala,akka,akka-stream,akka-http,java-websocket,Scala,Akka,Akka Stream,Akka Http,Java Websocket,目前,我们正在使用它向客户端发送消息 Flow[Message] .mapConcat(_ ⇒ Seq.empty[String].toList) .merge(source) // Stream the data we want to the client .map(data => TextMessage(data)) val source = Source.fromFuture(data).throttle(1, 1.second, 1, ThrottleMode.Sha

目前,我们正在使用它向客户端发送消息

Flow[Message]
  .mapConcat(_ ⇒ Seq.empty[String].toList)
  .merge(source) // Stream the data we want to the client
  .map(data => TextMessage(data))

val source = Source.fromFuture(data).throttle(1, 1.second, 1, ThrottleMode.Shaping).runWith(Sink.ignore)

现在,我想接收来自客户机的响应并相应地回复。我应该怎么做?

您的WS-flow当前正在忽略传入消息
mapConcat
应与传入的
TextMessage
BinaryMessage
匹配,并做出一致的响应

Flow[Message].mapConcat {
  case tm: TextMessage => TextMessage(Source.single("Hello ") ++ tm.textStream ++ Source.single("!")) :: Nil
  case bm: BinaryMessage =>
    bm.dataStream.runWith(Sink.ignore) // ignore binary message but drain content
    Nil
}