-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5b1a6b
commit 7d6aa1b
Showing
8 changed files
with
81 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package benchmark | ||
package akkahttp | ||
|
||
import akka.actor.ActorSystem | ||
import akka.http.scaladsl.Http | ||
import akka.http.scaladsl.model.ws.{BinaryMessage, Message} | ||
import akka.http.scaladsl.server.Directives.{handleWebSocketMessages, path} | ||
import akka.stream.scaladsl.Flow | ||
import scala.util.{Failure, Success} | ||
|
||
object AkkahttpWs extends App: | ||
given system: ActorSystem = ActorSystem("akkahttp-ws") | ||
import system.dispatcher | ||
import conf.port | ||
Http() | ||
.newServerAt("localhost", port) | ||
.bind: | ||
path(conf.path): | ||
handleWebSocketMessages: | ||
Flow[Message].collect: | ||
case bm: BinaryMessage.Strict => | ||
BinaryMessage.Strict(bm.data) | ||
case bm: BinaryMessage.Streamed => | ||
BinaryMessage.Streamed(bm.dataStream) | ||
.onComplete: | ||
case Success(binding) => | ||
println(s"Server is listening on ws://localhost:$port/wsecho") | ||
case Failure(e) => | ||
println(s"Server failed to start, exception=$e") | ||
system.terminate() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package benchmark | ||
package conf | ||
|
||
val port = 9011 | ||
val path = "wsecho" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package benchmark | ||
package ziohttp | ||
|
||
import zio.*, http.*, Method.GET, ChannelEvent.Read | ||
|
||
object ZiohttpWs extends ZIOAppDefault: | ||
val run = | ||
Server.serve( | ||
Routes(GET / conf.path -> handler(socketApp.toResponse)) | ||
).provide(Server.defaultWithPort(conf.port)) | ||
|
||
val socketApp: WebSocketApp[Any] = | ||
Handler.webSocket: channel => | ||
channel.receiveAll: | ||
case x @ Read(WebSocketFrame.Binary(_)) => | ||
channel.send(x) | ||
case _ => | ||
ZIO.unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters