MS Net Operators

Introduction to Net Operators

The Net Operators module provides a comprehensive set of tools for managing network connections, protocols, and data streams within the MS ecosystem. This documentation outlines the various operators available and their functionalities.

Core Operators

Connect

Establishes a network connection to a specified address and port.

Parameters:

Example:

Connect(host="example.com", port=80, protocol="TCP")

Listen

Starts a server that listens for incoming network connections on a specified port.

Parameters:

Example:

Listen(port=5000, protocol="TCP")

Receive

Reads data from an active network connection.

Parameters:

Example:


let client = Connect(host="localhost", port=5000);
let data = Receive(connection=client, maxLength=1024);

Send

Sends data over an active network connection.

Parameters:

Example:


let server = Listen(port=5000);
let client = Accept(server); // Assuming Accept operator exists
Send(connection=client, data="Hello, client!");

Close

Closes an active network connection.

Parameters:

Example:

Close(connection=myConnection);

Advanced Operators

Accept

Accepts an incoming connection on a listening socket.

Parameters:

Example:


let server = Listen(port=8080);
let newClient = Accept(listener=server);

UdpReceive

Receives data from a UDP socket.

Parameters:

Example:


let udpSocket = UdpCreate(); // Assuming UdpCreate operator exists
let (data, senderAddress) = UdpReceive(socket=udpSocket, maxLength=512);

UdpSend

Sends data to a specific address and port via UDP.

Parameters:

Example:


let udpSocket = UdpCreate();
UdpSend(socket=udpSocket, data="Hello UDP!", address="192.168.1.100", port=12345);

Error Handling

Network operations can encounter various errors. It is recommended to wrap these operations in error handling blocks. The exact syntax for error handling might depend on the broader MS scripting environment.

Data Types

Data transferred over the network is typically represented as either string or bytes. Ensure that data is correctly encoded and decoded as needed.

Common Use Cases