Netty-based HTTP server implementation for the Play Framework providing high-performance, asynchronous HTTP processing with WebSocket support.
—
NettyServer provides automatic WebSocket protocol support for Play Framework applications. When applications define WebSocket endpoints using Play's WebSocket API, NettyServer handles the HTTP upgrade handshake, frame processing, and connection management transparently.
NettyServer automatically detects and handles WebSocket upgrade requests from the standard HTTP request processing pipeline.
// NettyServer transparently handles WebSocket requests defined in Play applications
// No direct server configuration needed - WebSocket support is built-in
// WebSocket endpoints are defined using Play's standard WebSocket API
import play.api.mvc.WebSocket
import play.api.libs.iteratee.{Enumerator, Iteratee}
def websocketEndpoint = WebSocket.using[String] { request =>
val in = Iteratee.foreach[String](println)
val out = Enumerator("Hello WebSocket!")
(in, out)
}NettyServer implements the complete WebSocket protocol specification including:
WebSocket behavior can be configured through Netty server configuration.
// Configuration keys affecting WebSocket behavior
val nettyConfig = Map(
"play.server.netty.maxInitialLineLength" -> "4096",
"play.server.netty.maxHeaderSize" -> "8192",
"play.server.netty.maxChunkSize" -> "8192"
)Usage Examples:
import play.api.mvc._
import play.api.libs.iteratee._
import play.core.server.NettyServer
// Create server that handles WebSocket endpoints
val server = NettyServer.fromRouter() {
case GET -> Root / "ws" => WebSocket.using[String] { request =>
val in = Iteratee.foreach[String] { message =>
println(s"Received: $message")
}
val out = Enumerator("Welcome!")
(in, out)
}
case GET -> Root / "health" => Action { Ok("Server running") }
}
// WebSocket connections are handled automatically by NettyServer
// No additional server configuration requiredThe server exposes a trait for checking WebSocket upgrade capability.
trait WebSocketable {
/** Check if request has proper WebSocket upgrade headers */
def check: Boolean
/** Get specific header value */
def getHeader(header: String): String
}This trait is used internally by NettyServer to validate WebSocket upgrade requests before performing the handshake.
Install with Tessl CLI
npx tessl i tessl/maven-com-typesafe-play--play-netty-server-2-10