---
sidebar_position: 4
sidebar_label: Sending from your server
---

# Sending from your server

Your server sends to rooms and to users with its secret, the same way whether a browser or an app gets it ([sending in depth](../apps/sending.md)).

## To a room

**Node**

```ts
await realtime.to( 'order:1042' ).emit( 'updated', { status: 'shipped' } );
```

**PHP**

```php
$realtime->to( 'order:1042' )->emit( 'updated', [ 'status' => 'shipped' ] );
```

**Python**

```python
realtime.to("order:1042").emit("updated", {"status": "shipped"})
```

```kotlin
rt.join("order:1042").on("updated") { data, _ -> status = data.jsonObject["status"]?.jsonPrimitive?.content ?: status }
```

## Not back to the app that caused it

When the app asks your server to change something, it sends its own name on the connection, `rt.tab`, and your server leaves it out of the emit: the app has already shown the change.

```kotlin
val request = Request.Builder()
    .url("$server/orders/1042/status")
    .header("Authorization", "Bearer $token")
    .header("X-Realtime-Tab", rt.tab)
    .post(buildJsonObject { put("status", "shipped") }.toString().toRequestBody("application/json".toMediaType()))
    .build()
```

**Node**

```ts
await realtime.to( 'order:1042' ).except( req.get( 'x-realtime-tab' ) ).emit( 'updated', { status } );
```

**PHP**

```php
$realtime->to( 'order:1042' )->except( $_SERVER['HTTP_X_REALTIME_TAB'] ?? null )->emit( 'updated', [ 'status' => $status ] );
// Laravel: broadcast( new OrderUpdated( $order ) )->toOthers();
```

**Python**

```python
realtime.to("order:1042").except_tab(request.headers.get("X-Realtime-Tab")).emit("updated", {"status": status})
```

## To a user

What only one user should get, on every page and app they have open, without a room of yours:

**Node**

```ts
await realtime.toUser( 42 ).emit( 'notice', { text: 'Your order shipped' } );
```

**PHP**

```php
$realtime->toUser( 42 )->emit( 'notice', [ 'text' => 'Your order shipped' ] );
```

**Python**

```python
realtime.to_user(42).emit("notice", {"text": "Your order shipped"})
```

```kotlin
rt.on("notice") { data, _ -> toast(data.jsonObject["text"]?.jsonPrimitive?.content ?: "") }
viewModelScope.launch { rt.events("notice").collect { (notice, _) -> toast(notice.toString()) } }   // or as a flow
```

It reaches the app while it is connected. This SDK has no push yet: an app that is closed, or long in the background, hears it next time it opens only if it was also kept in the history of a room.

## Webhooks

What apps and pages send to rooms, and who comes online, reaches your server by webhook, as for your web pages ([webhooks](../apps/sending.md#webhooks)).
