WebSocket Protocol Support

WebSocket Mock Server

Test real-time applications with confidence

State machines, scenarios, and message sequencing built-in

Built for Real-Time Testing

Everything you need to mock WebSocket connections for complex real-time applications.

Scenario-Based State Machines

Define complex conversation flows with states, transitions, and conditional responses. Model multi-step interactions like authentication flows or order workflows.

Message Pattern Matching

Match incoming messages with regex, JSONPath, or exact values. Route messages to different handlers based on content, type, or metadata.

Subprotocol Negotiation

Support custom WebSocket subprotocols for specialized applications. Automatically negotiate and handle protocol-specific message formats.

Heartbeat & Ping-Pong

Built-in ping/pong handling keeps connections alive. Configure heartbeat intervals and automatic reconnection behavior.

Connection Lifecycle Management

Control connection timeouts, idle detection, and graceful shutdown. Track connection state and trigger events on open, close, or error.

Max Connections Per Endpoint

Limit concurrent connections to simulate capacity constraints. Test how your application handles connection limits and queuing.

Recording Support

Record real WebSocket traffic and replay it later. Capture entire conversation flows for deterministic testing and debugging.

Define Scenarios with State Machines

Create complex WebSocket interactions using declarative configuration. No code required.

# mockd.yaml - WebSocket mock configuration
mocks:
  - id: ws-chat
    type: websocket
    websocket:
      path: /ws/chat
      echoMode: true
      maxConnections: 100
      maxMessageSize: 65536
      idleTimeout: "5m"
      heartbeat:
        enabled: true
        interval: "30s"
        timeout: "10s"
      matchers:
        - match:
            type: exact
            value: "ping"
          response:
            type: text
            value: "pong"
        - match:
            type: json
            path: "$.type"
            value: "auth"
          response:
            type: json
            value:
              type: "authenticated"
              timestamp: "{{now}}"
        - match:
            type: json
            path: "$.type"
            value: "message"
          response:
            type: json
            value:
              type: "ack"
              id: "{{uuid}}"
              timestamp: "{{now}}"
      defaultResponse:
        type: json
        value:
          type: "echo"
          received: "{{message}}"
          timestamp: "{{now}}"

This example shows a chat authentication flow with state transitions, dynamic responses, and broadcasting.

Why Choose Mockd for WebSocket Testing?

Purpose-built for real-time application testing with features others lack.

vs MSW (Mock Service Worker)

Standalone server - Share with your whole team, test from any client

Not browser-only - Test mobile apps, CLI tools, and server-to-server

Full state machines - Complex conversation flows, not just request/response

vs mock-socket

Full server, not just a library - Test mobile apps too

Record real traffic - Capture and replay production WebSocket flows

Multi-protocol - Use the same tool for HTTP, GraphQL, gRPC, and more

Real-Time Use Cases

From chat apps to multiplayer games, Mockd handles any WebSocket testing scenario.

Chat Application Testing

Simulate multiple users, message delivery, typing indicators, and presence updates. Test edge cases like network interruptions.

Real-Time Dashboard Development

Mock streaming data feeds for dashboards. Test updates, reconnection logic, and data synchronization scenarios.

Gaming Backend Simulation

Simulate game servers with state machines. Test player actions, game events, and multiplayer synchronization.

Live Notification Testing

Mock push notification servers. Test delivery timing, batching, and user-specific notification routing.

Collaborative App Development

Simulate real-time collaboration features. Test concurrent editing, conflict resolution, and cursor synchronization.

Start Testing WebSockets Today

Single Go binary. No dependencies. Real WebSocket connections in seconds.

# Quick install
curl -sSL https://get.mockd.io | sh