# 08 — Networking via 39dll

5.3a has **zero native network functions**. Any multiplayer / client-server 5.3a game uses `39dll.dll` (or a near-identical wrapper). If decompiled GML calls `sendmessage` / `receivemessage` / `writebyte` etc. — that's 39dll.

## Why 39dll exists

GML 5.3a lacks byte-buffer types entirely. 39dll provides:

- TCP + UDP socket management.
- An internal contiguous memory buffer (in C++ land) for payload assembly.
- GML-callable wrapper functions via [`external_define()`](07-gml-core-functions.md).

Bound into the runtime via `DllStart()` or per-function `external_define` bindings.

## Standard workflow (every 39dll game)

### 1. Init
```
DllStart();                              // load DLL, init sockets
sock = createsocket(TCP);
connect(sock, ip, port);
```

### 2. Construct outgoing message
```
clearbuffer();
writebyte(MSG_TYPE_MOVE);
writedouble(x);
writedouble(y);
writestring(player_name);
```

### 3. Send
```
sendmessage(sock, ip, port);
```

### 4. Receive + deserialize
```
n = receivemessage(sock);                // returns bytes received
if (n > 0) {
    msgtype = readbyte();
    x       = readdouble();
    y       = readdouble();
    name    = readstring();
}
```

## Critical RE consequence: **packet structure = read/write call order**

There is **no** metadata wrapper, schema, JSON, XML, or framing. The wire format is **the literal sequence of `write*` calls** in the script.

Reconstructing a server emulator for a defunct 5.3a game means:

1. Find every `sendmessage` site in decompiled GML.
2. Trace backward to enumerate the exact `write*` sequence.
3. That sequence **is** the packet format.
4. Mirror it on the server side as raw byte unpacking in the same order.

Example: `writebyte(status)` then `writedouble(x)` = exactly 9 bytes on the wire (1 byte status + 8 byte double). No length prefix, no delimiters, no version byte unless the script emits one explicitly.

## Modern equivalents

"Boomers Networking" for GMS deliberately mimics 39dll's function names and ordering — useful as documentation cross-reference if 39dll docs are unavailable.

## See also

- [07-gml-core-functions](07-gml-core-functions.md) — `external_define`
- [05-gml-vm](05-gml-vm.md)
- [16-bno-bnb-notes](16-bno-bnb-notes.md) — same byte-stream pattern often used for save files
