CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-typesafe-play--play-netty-server-2-10

Netty-based HTTP server implementation for the Play Framework providing high-performance, asynchronous HTTP processing with WebSocket support.

Pending
Overview
Eval results
Files

websocket-support.mddocs/

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.

Capabilities

Automatic WebSocket Integration

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)
}

Protocol Support

NettyServer implements the complete WebSocket protocol specification including:

  • HTTP Upgrade Handshake: Automatic negotiation from HTTP to WebSocket protocol
  • Frame Processing: Support for text, binary, close, ping, and pong frames
  • Flow Control: Backpressure handling and connection management
  • Error Handling: Proper connection cleanup and error propagation

WebSocket Configuration

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 required

WebSocketable Trait

The 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

docs

index.md

server-components.md

server-management.md

websocket-support.md

tile.json