# WireStats

> The WireStats interface of the Client API counts a client's messages and bytes in and out, across reconnects.

The **`WireStats`** interface of the [Client API](/docs/client) counts a client's traffic since it was created, across reconnects: messages and bytes in and out, by message type, and the size of the last state update. A client's is [`room.stats`](/docs/client/room-client/stats).

## Instance properties

[`WireStats.messagesIn`](/docs/client/wire-stats/messagesin)
: The number of protocol messages received.

[`WireStats.bytesIn`](/docs/client/wire-stats/bytesin)
: The bytes of the protocol messages received.

[`WireStats.messagesOut`](/docs/client/wire-stats/messagesout)
: The number of protocol messages sent.

[`WireStats.bytesOut`](/docs/client/wire-stats/bytesout)
: The bytes of the protocol messages sent.

[`WireStats.received`](/docs/client/wire-stats/received)
: Messages and bytes received, by server message type. Read only.

[`WireStats.sent`](/docs/client/wire-stats/sent)
: Messages and bytes sent, by client message type. Read only.

[`WireStats.lastUpdate`](/docs/client/wire-stats/lastupdate)
: The last whole state update applied: its tick, the messages it was split into and their size.

## Description

Sizes are of protocol messages as encoded, without the transport's own framing, such as a WebSocket frame header. The client updates the counters as messages pass; your code only reads them. To get rates, sample them at an interval and take the difference.

## Examples

### Showing bandwidth in a debug overlay

A debug overlay samples the counters once a second and shows the traffic in each direction.

```ts
// bandwidth.ts
import type { ReadyRoomClient } from "@irtio/client";

export function showBandwidth(room: ReadyRoomClient, show: (line: string) => void) {
  let last = { in: room.stats.bytesIn, out: room.stats.bytesOut };
  return setInterval(() => {
    const now = { in: room.stats.bytesIn, out: room.stats.bytesOut };
    show(`down ${((now.in - last.in) / 1024).toFixed(1)} KB/s, up ${((now.out - last.out) / 1024).toFixed(1)} KB/s`);
    last = now;
  }, 1000);
}
```

## See also

- [`RoomClient.stats`](/docs/client/room-client/stats)
- [Testing](/docs/tools/testing#testclient), for checking what a game costs on the wire in a test
- [Compact inputs](/docs/client/guides/prediction#compact-inputs), for cutting what prediction inputs cost
