WebSockets in Mendix: The Complete Real-Time Communication Guide

WebSockets in Mendix

Modern applications no longer rely solely on page refresh or API calls. Users expect instant updates, live syncing, and real-time interaction—whether it’s dashboards, chat apps, or stock price updates. WebSockets are a game-changer for Mendix developers, enabling seamless real-time communication across your applications.

What is WebSocket?

REST API vs WebSocket

  • REST API = "Polling"

  • WebSocket = "Live conversation"

Key Features of WebSockets

  • Full-duplex communication

  • Single, always-open connection

  • Lightweight protocol

  • Real-time data transmission

  • Low latency

Once the WebSocket connection opens, both client and server can push messages instantly without page reloads.

How WebSocket Works in Mendix

Step 1: Handshake

  • Browser sends an Upgrade request

  • Server agrees → Upgrades HTTP → WebSocket

Step 2: Persistent Connection

  • Connection stays open until closed manually

  • No need to re-open like REST

Step 3: Two-Way Data Flow

  • Client → Server

  • Server → Client
    Both can send messages anytime

Step 4: Real-Time Events

  • Server messages instantly update the UI

  • Ideal for dashboards, chat, and real-time alerts

Why WebSockets Are Important in Mendix

Default Mendix behavior:

  • APIs run only when triggered

  • UI refresh needed

  • Microflows run on demand

Modern apps need:

  • Live dashboards

  • Auto-refresh data

  • Instant notifications

  • Multi-user collaboration

WebSockets bridge this gap, enabling real-time updates without page refresh for a modern user experience.

Use Cases of WebSockets in Mendix

Real-Time Dashboards

  • Sales, production, inventory tracking updated instantly

Auto Logout (Multi-Device Login Control)

  • User logs in from another device → previous device logs out immediately

: In-App Chat & Messaging

  • Live messaging within Mendix apps

Live Notifications

  • Admin triggers updates → visible to all users in real-time

Mendix Marketplace: EZ WebSocket Module (Single App Only)

Features:

  • Real-time UI updates

  • Broadcast messages to all users

  • Publish/Subscribe channels

  • Trigger nanoflow when a message arrives

  • Auto-refresh widgets

  • Auto logout mechanisms

Communication Between Two Different Mendix Apps

Note : EZ WebSocket is single app only. For multi-app communication, use an external WebSocket server.

Architecture:

  • App A → Sends data to WebSocket Server (REST)

  • WebSocket Server (Node.js/Java) → Broadcasts messages

  • App B → Connects as WebSocket client → Receives messages instantly

Tools :

  • Node.js WebSocket Server: Fast, easy, production ready (Recommended)

  • Java WebSocket Server: JSR-356 standard, can run inside Mendix via Java actions

  • External Services: Pusher, Ably, PubNub, Firebase

WebSocket Creation and Hosting (External Server)

Node.js WebSocket Server Example:

Hosting Options:

  • AWS EC2

  • Azure VM

  • DigitalOcean

  • Local Server

  • Docker container

Mendix apps can now connect to this server for real-time communication.

Connecting Mendix to External WebSocket Server

Steps:

  • 1. Create Java Action (connect)

  • 2. Create Java Action (send message)

  • 3. Create Java Action (disconnect)

  • 4. Use DataHub/Manager to store connection instance

  • 5. Triggering events by publishing messages

  • 6. Subscribe in Mendix to show changes in real-time

This enables :

  • Mendix ↔ Node.js real-time

  • App A ↔ App B real-time

  • Mendix ↔ IoT devices

  • Mendix ↔ Stock servers

  • Mendix ↔ ERP systems

What’s Next?

  • Keep messages small (text-based)

  • Use JSON for structured data

  • Ensure error handling in Java actions

  • Use external server for scalability

  • Avoid opening WebSocket connections on every page

  • Close socket on logout

  • Test network stability

  • Enterprise recommendation: Kafka/WebSocket Gateway

Conclusion

WebSockets bring real-time power to Mendix apps:

  • Instant UI updates

  • Live dashboards

  • Auto logout

  • Notifications

  • Multi-user collaboration

  • Multi-app communication

Mendix’s EZ WebSocket module is perfect for single-app real-time needs. For enterprise-grade multi-app communication, custom WebSocket servers with Java actions are recommended.

Want to implement WebSockets in your Mendix applications? Contact MXTechies today and take your business apps to the next level with real-time functionality.