BOSH (Bidirectional-streams Over Synchronous HTTP) is the transport protocol defined in XEP-0124 and XEP-0206 that lets XMPP clients communicate with servers over ordinary HTTP requests instead of a persistent TCP socket. Strophe.js selects BOSH automatically whenever you pass anDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/strophe/strophejs/llms.txt
Use this file to discover all available pages before exploring further.
http:// or https:// URL — or any path that does not begin with ws: or wss: — to new Strophe.Connection().
When to Use BOSH
Use BOSH when…
- Corporate firewalls or proxies block WebSocket upgrades
- You need broad compatibility with legacy infrastructure
- Server-side session prebinding is required (XEP-0124
attach) - You want built-in keepalive via
sessionStorage
Prefer WebSocket when…
- Low latency and high message throughput matter
- Your server and network infrastructure support WebSocket
- You do not need HTTP-proxy compatibility
Connection URL Format
Strophe.js detects BOSH from the URL scheme. Any URL beginning withhttp:// or https://, or a relative path, is treated as a BOSH endpoint.
Basic BOSH Connection
http:// scheme and instantiates a Bosh transport internally. No extra configuration is needed for a straightforward connection.
BOSH-Specific Connection Options
All options below are passed as the second argument tonew Strophe.Connection(service, options).
sync — Synchronous Requests
By default all BOSH HTTP requests are asynchronous. Setting sync: true makes Strophe.js use synchronous XMLHttpRequest calls instead. This is occasionally useful in Node.js scripts or unit tests but should never be used in a browser UI because it blocks the event loop.
customHeaders — Extra HTTP Headers
Pass an object whose keys are header names and values are header values. Strophe.js sets these headers on every outgoing XMLHttpRequest.
keepalive — Persist Sessions Across Reloads
When keepalive is true, Strophe.js serialises the BOSH session tokens (jid, rid, sid) into sessionStorage after every request. On the next page load you can restore the session with connection.restore() without re-authenticating.
restore().
cookies — Include Cookies in Requests
Pass a map of cookie definitions to have Strophe.js attach them to every BOSH HTTP request. Note that cookies set this way are scoped to the same domain as the page — cross-domain cookies must be set server-side.
withCredentials — Cross-Origin Cookies
Set withCredentials: true to include cookies when making cross-origin BOSH requests. The BOSH server must respond with Access-Control-Allow-Credentials: true and a concrete (non-wildcard) Access-Control-Allow-Origin header for this to work.
BOSH Keepalive Example
Bosh Class Internals
TheBosh class is the internal transport object stored at connection._proto when BOSH is active. You generally do not interact with it directly, but understanding its properties helps with debugging and advanced configuration.
| Property | Default | Description |
|---|---|---|
rid | random 32-bit int | The current BOSH request ID, incremented with each body sent |
sid | null | Session identifier assigned by the server on first connection |
hold | 1 | Number of connections the server holds open simultaneously |
wait | 60 | Seconds the server waits before returning an empty response |
window | 5 | Allowed range of valid request IDs (pipelining window) |
errors | 0 | Consecutive request error count; disconnects after 5 errors |
inactivity | null | Max inactivity seconds the server will tolerate (set by server) |
strip | false | Strip the <body> wrapper from xmlInput/xmlOutput callbacks |
Stripping the <body> Wrapper
Every BOSH stanza is wrapped in a <body> element defined by the HTTPBIND namespace. By default Strophe.js passes the full <body> element to your xmlInput and xmlOutput callbacks. If you prefer to receive individual XMPP stanzas directly, set strip to true:
Timeout Configuration
BOSH timeouts are controlled by two multipliers on theStrophe namespace. Both values are multiplied against the negotiated wait time to derive actual timeouts.
| Property | Default multiplier | Description |
|---|---|---|
Strophe.TIMEOUT | 1.1 | Primary timeout multiplier — triggers request restart when exceeded |
Strophe.SECONDARY_TIMEOUT | 0.1 | Secondary timeout multiplier — applies when a request is already considered “dead” |
wait value or when operating over high-latency networks.
Connection Pooling: hold and wait
The default hold=1 means Strophe.js keeps at most one HTTP request open on the server at a time. The server holds the request for up to wait=60 seconds and responds either with XMPP stanzas to deliver or an empty body. This makes BOSH behave like a long-poll connection.
You can pass wait and hold overrides to connection.connect():
Increasing
hold above 1 or decreasing wait below the default can increase server load. Most deployments work well with the defaults.