1

Vert.x Scala ライブラリ (バージョン 3.8.0) を使用していますが、websocket 接続をセットアップしてメッセージを送信する方法がわかりません。Vert.x 3.5.4のドキュメントの指示に従うと、これは機能するはずです。

import io.vertx.scala.core.Vertx
import io.vertx.scala.core.http.HttpClientOptions

object WsClient extends App {
  val vertx = Vertx.vertx
  val client = vertx.createHttpClient

  client.websocket(8080, "localhost", "/api", (ws: io.vertx.scala.core.http.WebSocket) => {
    println("connected")
    val message = "hello"
    ws.writeTextMessage(message)
  })
}

ただし、コンパイル時に次のエラーがスローされます。

Error:(9, 10) overloaded method value websocket with alternatives:
  (requestURI: String,headers: io.vertx.scala.core.MultiMap,version: io.vertx.core.http.WebsocketVersion,wsConnect: io.vertx.core.Handler[io.vertx.scala.core.http.WebSocket])io.vertx.scala.core.http.HttpClient <and>
  (requestURI: String,headers: io.vertx.scala.core.MultiMap,wsConnect: io.vertx.core.Handler[io.vertx.scala.core.http.WebSocket],failureHandler: io.vertx.core.Handler[Throwable])io.vertx.scala.core.http.HttpClient <and>
  (options: io.vertx.scala.core.http.RequestOptions,headers: io.vertx.scala.core.MultiMap,version: io.vertx.core.http.WebsocketVersion,wsConnect: io.vertx.core.Handler[io.vertx.scala.core.http.WebSocket])io.vertx.scala.core.http.HttpClient <and>
  (host: String,requestURI: String,headers: io.vertx.scala.core.MultiMap,wsConnect: io.vertx.core.Handler[io.vertx.scala.core.http.WebSocket])io.vertx.scala.core.http.HttpClient <and>
  (options: io.vertx.scala.core.http.RequestOptions,headers: io.vertx.scala.core.MultiMap,wsConnect: io.vertx.core.Handler[io.vertx.scala.core.http.WebSocket],failureHandler: io.vertx.core.Handler[Throwable])io.vertx.scala.core.http.HttpClient <and>
  (host: String,requestURI: String,wsConnect: io.vertx.core.Handler[io.vertx.scala.core.http.WebSocket],failureHandler: io.vertx.core.Handler[Throwable])io.vertx.scala.core.http.HttpClient <and>
  (port: Int,host: String,requestURI: String,wsConnect: io.vertx.core.Handler[io.vertx.scala.core.http.WebSocket])io.vertx.scala.core.http.HttpClient
 cannot be applied to (Int, String, String, io.vertx.scala.core.http.WebSocket => io.vertx.scala.core.http.WebSocket)
  client.websocket(8080, "localhost", "/api", (ws: io.vertx.scala.core.http.WebSocket) => {

また、言語にハンドラーの型を推測させようとしましたが、成功しませんでした。私は何を間違っていますか?

4

1 に答える 1