Files
bitburner-src/markdown/bitburner.ns.writeport.md

81 lines
1.3 KiB
Markdown

<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [bitburner](./bitburner.md) &gt; [NS](./bitburner.ns.md) &gt; [writePort](./bitburner.ns.writeport.md)
## NS.writePort() method
Write data to a port.
**Signature:**
```typescript
writePort(portNumber: number, data: any): any;
```
## Parameters
<table><thead><tr><th>
Parameter
</th><th>
Type
</th><th>
Description
</th></tr></thead>
<tbody><tr><td>
portNumber
</td><td>
number
</td><td>
Port to write to. Must be a positive integer.
</td></tr>
<tr><td>
data
</td><td>
any
</td><td>
Data to write, it's cloned with structuredClone().
</td></tr>
</tbody></table>
**Returns:**
any
The data popped off the queue if it was full, or null if it was not full.
## Remarks
RAM cost: 0 GB
Write data to the given Netscript port.
There is a limit on the maximum number of ports, but you won't reach that limit in normal situations. If you do, it usually means that there is a bug in your script that leaks port data. A port is freed when it does not have any data in its underlying queue. `ns.clearPort` deletes all data on a port. `ns.readPort` reads the first element in the port's queue, then removes it from the queue. Ports are shared across all hosts and contents are reset on game restart.