Netscript Ports

Netscript ports are endpoints that can be used to communicate between scripts. A port is implemented as a sort of serialized queue, where you can only write and read one element at a time from the port. When you read data from a port, the element that is read is removed from the port.

The read and write Netscript functions are used to read and write from a port.

Right now, there are only 10 ports for Netscript, denoted by the number 1 through 10. When using the read and write functions, the ports are specified by passing the number as the first argument.

IMPORTANT: The data inside ports are not saved! This means if you close and re-open the game, or reload the page then you will lose all of the data in the ports!

Example
Here's a brief example of how ports work. For the sake of simplicity we'll only deal with port 1.

Let's assume Port 1 starts out empty (no data inside). We'll represent the port as such:

Now assume we ran the following simple script:

After this script executes, our port will contain every number from 0 through 9, as so:

Then, assume we run the following script:

This script above will read the first three values from port 1 and then print them to the script's log. The log will end up looking like:

And the data in port 1 will look like: