---
title: OpenClient
project: Total.js V5
version: 0.0.20
section: guides
language: en
license: MIT
url: https://totaljs.es/docs/total-js-v5/0-0-20/guides/openclient/
updated: 2026-11-16T15:58:11.814Z
---

# OpenClient

> Open a WebSocket connection to another service with OPENCLIENT() and send messages that wait for an answer.

`OPENCLIENT(url, [id])` opens a WebSocket connection to another service and lets you send messages that wait for an answer. Several clients with the same URL share one connection, which reconnects by itself.

```js
var client = OPENCLIENT('https://service.example.com/$client/');

client.online(function(meta) {
	console.log(meta ? 'online' : 'offline');
});

client.message(function(msg) {
	console.log('Message', msg);
});

var result = await client.rpc({ type: 'users' }, 5000);
```

`rpc()` adds a `callbackid` to the message; the service answers with `{ callbackid, error, response }`. For WebSocket routes in your own application read [WebSockets](../websockets/).
