> ## Documentation Index
> Fetch the complete documentation index at: https://gluals.arnux.net/llms.txt
> Use this file to discover all available pages before exploring further.

# Network analysis

> Check network message registration, senders, receivers, and payload order across realms.

## Overview

GMod networking requires senders and receivers to use the same message name and payload layout. GLuaLS connects these calls across your workspace and reports mistakes before you run the game.

***

## What is validated

### Message registration

Every `net.Start(name)` call must have a corresponding `util.AddNetworkString(name)`.

In real Garry's Mod code, `util.AddNetworkString` must run on the server. GLuaLS checks for that registration across the workspace so it can still connect senders and receivers across files.

```lua theme={null}
-- Error: "PlayerData" is not registered with util.AddNetworkString
net.Start("PlayerData")
net.WriteString("test")
net.Broadcast()
```

```lua theme={null}
-- Registered on the server
util.AddNetworkString("PlayerData")  -- in a sv_ file or SERVER block

net.Start("PlayerData")
net.WriteString("test")
net.Broadcast()
```

### Missing counterpart

Each `net.Start(name)` sender should have a matching `net.Receive(name)` receiver in the expected realm:

```lua theme={null}
-- sv_comms.lua: sends "PlayerInfo" to client
net.Start("PlayerInfo")
net.WriteString(ply:Nick())
net.Send(ply)

-- Warning: no net.Receive("PlayerInfo") was found
```

### Read/write type mismatch

The `net.Read*` call sequence must match the `net.Write*` call sequence for the same message type:

```lua theme={null}
-- Server writes:
net.Start("EntityData")
net.WriteEntity(ent)   -- WriteEntity first
net.WriteString(name)  -- WriteString second

-- Client reads:
net.Receive("EntityData", function()
    local name = net.ReadString()  -- Reads a string where an entity was written
    local ent  = net.ReadEntity()  -- Reads an entity where a string was written
end)
```

### Conditional and repeated payloads

GLuaLS understands reads and writes inside `if`, `for`, `while`, and `repeat` blocks. It treats these operations as optional or repeated instead of reporting a simple count mismatch.

If both sides use compatible loops or branches, they are matched as the same payload flow. When the code is too dynamic to compare safely, GLuaLS avoids guessing.

***

## Aliases and wrappers

Aliases and wrappers around the standard GMod network functions work automatically. You do not need to add annotations to them.

For example, you can use local aliases:

```lua theme={null}
local netStart = net.Start
local netSend  = net.Broadcast

netStart("MyMessage")
net.WriteString("hello")
netSend()
```

You can also put a complete network message in a helper function:

```lua theme={null}
function MyLib.SendGreeting(messageName, greeting)
    net.Start(messageName)
    net.WriteString(greeting)
    net.SendToServer()
end

local sendGreeting = MyLib.SendGreeting
sendGreeting("Greeting", "hello")
```

GLuaLS also supports read and write helpers, receive helpers, and helpers that split `net.Start` from the final send call.

<Note>
  If your library replaces the GMod network API instead of calling `net.*`, use [`@call_arg`](/annotations/call-arg) for message names and receive callbacks, `net_send` for send functions, and `net_payload` for read and write functions. Normal wrappers do not need these attributes.
</Note>

***

## Diagnostic codes

| Code                                   | Description                                                                                           |
| -------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| `gmod-unknown-net-message`             | `net.Start(name)` uses a name not registered with `util.AddNetworkString`                             |
| `gmod-net-missing-network-counterpart` | A sender or receiver exists, but GLuaLS found no matching counterpart with the same message name      |
| `gmod-net-read-write-type-mismatch`    | `net.Read*` type doesn't match the `net.Write*` type for the same sequence position                   |
| `gmod-net-read-write-order-mismatch`   | The order of reads doesn't match the order of writes                                                  |
| `gmod-net-read-write-bits-mismatch`    | Literal bit-width argument differs between a matched `net.WriteUInt`/`net.ReadUInt` (or similar) pair |

***

## Smart completions

GLuaLS completes known message names in `net.Start()` and `net.Receive()`. Inside a receive callback, it can also suggest the expected `net.Read*` calls in payload order.

## Hover and navigation

Hover over a network message name to see its known senders, receivers, and payload layout. Code lenses show how many matching senders and receivers exist and let you jump to them.

***

## Cross-file tracking

Network analysis works across files. GLuaLS tracks messages registered in one file, sent in a second, and received in a third as one flow.

***

## Configuration

Most network flow checks are configured under `gmod.network`.

Disable all network flow analysis with `gmod.network.enabled`. To silence one diagnostic code, use `diagnostics.disable` with the code name, such as `"gmod-net-read-write-type-mismatch"`.

See the [Garry's Mod settings](/configuration/gmod#network-analysis) for the full reference on network-related configuration options.

***

## Limitations

* Message names must resolve to a known string. A value such as `"msg" .. id` cannot be connected to one message flow.
* Code outside your workspace or configured libraries cannot count as a sender, receiver, or registration.
* Runtime behavior that cannot be determined from the code is skipped rather than guessed.

## VS Code integration

Network diagnostics run in the background. Diagnostics appear as squiggly underlines and in the Problems panel. Configure them in the [settings panel](/configuration/overview#settings-panel-recommended). See [Garry's Mod settings](/configuration/gmod) for the full network configuration reference.
