Object «mailbox»

This article is automatically translated from Russian by Google Translator.

It implements communication between robots in the network by means of the mailbox mechanism.

Method

Description

connect

Connects to the robot with a given IP address on a given port (or default port), gives it its on-board number, and registers with the "mailbox" network.

hasMessages

Returns true if the robot received a new message.

myHullNumber

Returns the onboard number of the robot.

newMessage

Sends a message after receiving a message.

receive

Gets a new message or blocks script execution until the message arrives.

send

Sends the specified message to the robot with the specified board number (or all robots).

connect

Connects to the robot with a given IP address on a given port (or default port), gives it its on-board number, and registers with the "mailbox" network.

Syntax

Python
JavaScript
Python
mailbox.connect("ipAddress")
mailbox.connect("ipAddress", port)
JavaScript
mailbox.connect("ipAddress");
mailbox.connect("ipAddress", port);

As parameters, you must specify the IP address of the robot and the port. If no port is specified, the default port is used.

Example

Python
JavaScript
Python
mailbox.connect("192.168.0.20", 8889)
JavaScript
mailbox.connect("192.168.0.20", 8889);

hasMessages

Returns true if the robot received a new message.

Syntax

Python
JavaScript
Python
mailbox.hasMessages()
JavaScript
mailbox.hasMessages();

myHullNumber

Returns the onboard number of the robot.

Syntax

Python
JavaScript
Python
x = mailbox.myHullNumber()
JavaScript
var x = mailbox.myHullNumber();

newMessage

Sends a message after receiving a message.

Syntax

Python
JavaScript
Python
mailbox.newMessage.connect(lambda sender, message: print(message))
JavaScript
mailbox.newMessage.connect(function(sender, message) { print(message); });

The first parameter is the sender's onboard number, the second is the message itself.

receive

Gets a new message or blocks script execution until the message arrives.

Syntax

Python
JavaScript
Python
message = mailbox.receive()
JavaScript
var message = mailbox.receive();

send

Sends the specified message to the robot with the specified board number (or all robots).

Syntax

Python
JavaScript
Python
mailbox.send("message")
mailbox.send(boardNumber, "message")
JavaScript
mailbox.send("message");
mailbox.send(boardNumber, "message");

As a parameter, you must specify the on-board number of the robot to which you want to send the message and the message. If no on-board number is specified, the message is sent to all robots registered in the network.

Example

Python
JavaScript
Python
mailbox.send(1, "Hello") # Sending a message to a robot with board number 1
JavaScript
mailbox.send(1, "Hello"); // Sending a message to a robot with board number 1