loci.communicator.ws.jetty.WSConnector.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scala-loci-communicator-ws-jetty_2.13 Show documentation
Show all versions of scala-loci-communicator-ws-jetty_2.13 Show documentation
ScalaLoci Jetty WebSocket communicator
The newest version!
package loci
package communicator
package ws.jetty
import org.eclipse.jetty.websocket.client.WebSocketClient
import java.net.URI
import scala.util.{Failure, Success}
private class WSConnector[P <: WS : WSProtocolFactory](
url: String, properties: WS.Properties)
extends Connector[P] {
protected def connect(connectionEstablished: Connected[P]): Unit = {
val uri = URI.create(url)
val tls = uri.getScheme == "wss"
implicitly[WSProtocolFactory[P]].make(
url, Some(uri.getHost), Some(uri.getPort),
this, tls, tls, tls, None) match {
case Failure(exception) =>
connectionEstablished.set(Failure(exception))
case Success(ws) =>
val socket = new Socket(ws, properties)(connectionEstablished.trySet(_), connectionEstablished.trySet(_))
val client = new WebSocketClient()
client.start()
client.connect(socket, uri)
socket.doClosed.notice foreach { _ => client.stop() }
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy