Binary Protocol (Advanced / Contributors)
This document is for advanced users and contributors. Most users do not need to read this — Transit handles all communication automatically. If you are just getting started, see Getting Started instead.
This page describes the wire format Transit uses to communicate between JavaScript and Java/Python. You do not need to read this to use Transit — it is for contributors and advanced users who want to understand how the communication works.
Overview
Section titled “Overview”When JavaScript calls a Python or Java function, it sends a small binary message over a network connection. Here are the key facts:
Note on Rust, C, and C++: These languages run in-process as native Node.js addons via the
RustDevBridge. They do not use this binary protocol and communicate directly in-process with zero serialization overhead.
- Transport: TCP on
127.0.0.1(your computer only, not the internet) - Byte order: Little-endian (the standard for most computers)
- Protocol version: 1
- Message model: Request-response (each request gets exactly one response)
- Shared by: Java and Python bridges (identical protocol)
Header Format
Section titled “Header Format”Every message starts with a 10-byte header:
| Offset | Size | Field | Description |
|---|---|---|---|
| 0 | 1 | version | Always 1 |
| 1 | 1 | type | Message type (see below) |
| 2 | 4 | request_id | Pairs requests with responses |
| 6 | 4 | payload_len | Length of the payload that follows |
Message Types
Section titled “Message Types”| Byte | Name | Direction | What it does |
|---|---|---|---|
| 0x01 | CALL_REQUEST | JS -> Java/Python | “Please call this function” |
| 0x02 | CALL_RESPONSE | Java/Python -> JS | “Here is the result” |
| 0x03 | HEALTH_PING | JS -> Java/Python | “Are you still alive?” |
| 0x04 | HEALTH_PONG | Java/Python -> JS | “Yes, I am here” |
What a Function Call Looks Like
Section titled “What a Function Call Looks Like”When JavaScript calls processData({"items": [1, 2, 3]}):
-
JavaScript sends:
- Header: version=1, type=CALL_REQUEST, request_id=1, payload_len=34
- Payload: function name “processData” + arguments JSON
-
Python/Java receives:
- Reads the header
- Finds the function “processData”
- Calls it with the arguments
- Gets the result
-
Python/Java sends back:
- Header: version=1, type=CALL_RESPONSE, request_id=1, payload_len=…
- Payload: status=OK + result JSON
-
JavaScript receives:
- Matches the request_id
- Returns the result to your code
Health Checks
Section titled “Health Checks”Every 5 seconds, JavaScript sends a HEALTH_PING to make sure the Java/Python process is still running. If it does not respond, Transit restarts the process.
Connection Lifecycle
Section titled “Connection Lifecycle”- JavaScript starts the Java/Python process
- The process prints its port number to the console
- JavaScript connects to that port
- JavaScript sends a health check to verify the connection
- Normal operation: function calls and responses
- If the process crashes, JavaScript restarts it automatically
Error Handling
Section titled “Error Handling”- Connection timeout: 10 seconds
- Call timeout: 30 seconds per call
- Health check interval: 5 seconds
- Max restarts: 3 attempts with exponential backoff (1s, 2s, 3s)
- Graceful shutdown: SIGTERM sent, then SIGKILL after 5 seconds
Security
Section titled “Security”- The server binds to
127.0.0.1only — never exposed to the network - The server rejects non-loopback connections
- Each call has a unique request ID for response matching
- The protocol is not encrypted (not needed for loopback)