Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

readme.md

Table of Contents

UnetSocket

Creates a new UnetSocket to connect to a running Unet instance. This constructor returns a Promise instead of the constructed UnetSocket object. Use await or .then() to get a reference to the UnetSocket object. Based on if this is run in a Browser or Node.js, it will internally connect over WebSockets or TCP respectively.

Parameters

  • hostname string? hostname/ip address of the master container to connect to
  • port string? port number of the master container to connect to
  • path string path of the master container to connect to (for WebSockets) (optional, default '')

Examples

let socket = await new UnetSocket('localhost', 8081, '/ws/');

Returns Promise<UnetSocket> Promise which resolves to the UnetSocket object being constructed

close

Closes the socket. The socket functionality may not longer be accessed after this method is called.

Returns void

isClosed

Checks if a socket is closed.

Returns boolean true if closed, false if open

bind

Binds a socket to listen to a specific protocol datagrams. Protocol numbers between Protocol.DATA+1 to Protocol.USER-1 are reserved protocols and cannot be bound. Unbound sockets listen to all unreserved

Parameters

  • protocol Protocol protocol number to listen for

Returns boolean true on success, false on failure

unbind

Unbinds a socket so that it listens to all unreserved protocols. Protocol numbers between Protocol.DATA+1 to Protocol.USER-1 are considered reserved.

Returns void

isBound

Checks if a socket is bound.

Returns boolean true if bound to a protocol, false if unbound

connect

Sets the default destination address and destination protocol number for datagrams sent using this socket. The defaults can be overridden for specific send() calls. The default protcol number when a socket is opened is Protcol.DATA. The default node address is undefined. Protocol numbers between Protocol.DATA+1 to Protocol.USER-1 are considered reserved, and cannot be used for sending datagrams using the socket.

Parameters

  • to number default destination node address
  • protocol Protocol default protocol number

Returns boolean true on success, false on failure

disconnect

Resets the default destination address to undefined, and the default protocol number to Protocol.DATA.

Returns void

isConnected

Checks if a socket is connected, i.e., has a default destination address and protocol number.

Returns boolean true if connected, false otherwise

getLocalAddress

Gets the local node address of the Unet node connected to.

Returns Promise<int> local node address, or -1 on error

getLocalProtocol

Gets the protocol number that the socket is bound to.

Returns number protocol number if socket is bound, -1 otherwise

getRemoteAddress

Gets the default destination node address for a connected socket.

Returns number default destination node address if connected, -1 otherwise

getRemoteProtocol

Gets the default transmission protocol number.

Returns number default protocol number used to transmit a datagram

setTimeout

Sets the timeout for datagram reception. A timeout of 0 means the receive method will check any appropriate Datagram has already been received (and is cached) else return immediately.

Parameters

  • ms number timeout in milliseconds

Returns void

getTimeout

Gets the timeout for datagram reception.

Returns number timeout in milliseconds

setTTL

Sets the default time-to-live for datagrams sent using this socket. TTL is advisory; an agent may choose to ignore it.

Parameters

  • ttl number time-to-live in seconds

Returns void

getTTL

Gets the default time-to-live for datagrams sent using this socket.

Returns number time-to-live in seconds, or NaN if not set

setPriority

Sets the default priority for datagrams sent using this socket.

Parameters

  • priority any priority value; interpretation is provider-dependent

Returns void

getPriority

Gets the default priority for datagrams sent using this socket.

Returns any priority value, or null if not set

setReliability

Sets the default reliability for datagrams sent using this socket. When set to true, the socket will request reliable delivery and, in SEMI_BLOCKING mode, will wait for a delivery confirmation before returning.

Parameters

  • reliability boolean true for reliable delivery, false for unreliable

Returns void

getReliability

Gets the default reliability setting for datagrams sent using this socket.

Returns (boolean | null) true if reliable, false if unreliable, null if not set

setRoute

Sets the default route identifier for datagrams sent using this socket. Route selection is provider-dependent; not all providers support explicit routing.

Parameters

  • route any route identifier

Returns void

getRoute

Gets the default route identifier for datagrams sent using this socket.

Returns any route identifier, or null if not set

setMimeType

Sets the default MIME type describing the datagram payload. This can be used by REMOTE service providers to apply content-aware compression.

Parameters

  • mimeType string MIME type string (e.g. 'application/json')

Returns void

getMimeType

Gets the default MIME type for datagrams sent using this socket.

Returns (string | null) MIME type string, or null if not set

setRemoteRecipient

Sets the default remote recipient for datagrams sent using this socket. Used by REMOTE service providers to address a specific entity on the remote node.

Parameters

  • remoteRecipient any remote recipient identifier (e.g. an AgentID or name string)

Returns void

getRemoteRecipient

Gets the default remote recipient for datagrams sent using this socket.

Returns any remote recipient identifier, or null if not set

setMailbox

Sets the default mailbox name for datagrams sent using this socket. Mailboxes are used by REMOTE service providers to deliver messages to a named queue on the remote node.

Parameters

Returns void

getMailbox

Gets the default mailbox name for datagrams sent using this socket.

Returns (string | null) mailbox name, or null if not set

setMessageClass

Sets the default application message class for datagrams sent using this socket. Used by REMOTE service providers to associate a fully-qualified class name with the payload.

Parameters

  • messageClass string fully-qualified message class name (e.g. 'org.example.Status')

Returns void

getMessageClass

Gets the default application message class for datagrams sent using this socket.

Returns (string | null) message class name, or null if not set

setServiceProvider

Overrides the service provider used to transmit datagrams. When set, provider auto-selection is bypassed and all sends go through the specified agent. Pass null to re-enable auto-selection.

Parameters

  • provider (AgentID | string | null) agent id, agent name string, or null to clear the override

Returns void

getServiceProvider

Gets the currently configured service provider override.

Returns (AgentID | null) the override agent id, or null if auto-selection is active

setSendMode

Sets the send mode that controls how send() behaves after the provider accepts a request:

  • UnetSocket.NON_BLOCKING (0): returns immediately after the provider agrees.
  • UnetSocket.SEMI_BLOCKING (1): if reliability is not true, returns after AGREE; otherwise waits for a delivery confirmation (RemoteDeliveryNtf / DatagramDeliveryNtf) or failure.
  • UnetSocket.BLOCKING (2): waits for a transmission or delivery notification (DatagramTransmissionNtf, DatagramDeliveryNtf) before returning. The default is SEMI_BLOCKING.

Parameters

  • sendMode number one of UnetSocket.NON_BLOCKING, SEMI_BLOCKING, or BLOCKING

Returns void

getSendMode

Gets the current send mode.

Returns number current send mode (NON_BLOCKING=0, SEMI_BLOCKING=1, BLOCKING=2)

send

Transmits a datagram to the specified node address using the specified protocol. Protocol numbers between Protocol.DATA+1 to Protocol.USER-1 are considered reserved, and cannot be used for sending datagrams using the socket.

Parameters

  • data (Array<number> | DatagramReq) data to be sent over the socket as an Array of bytes or DatagramReq
  • to number destination node address (optional, default this._remoteAddress)
  • protocol number protocol number (optional, default this._remoteProtocol)

Returns Promise<boolean> true if the Unet node agreed to send out the Datagram, false otherwise

receive

Receives a datagram sent to the local node and the bound protocol number. If the socket is unbound, then datagrams with all unreserved protocols are received. Any broadcast datagrams are also received.

Returns Promise<DatagramNtf?> datagram received by the socket

getGateway

Gets a Gateway to provide low-level access to UnetStack.

Returns Gateway underlying fjage Gateway supporting this socket

agentForService

Gets an AgentID providing a specified service for low-level access to UnetStack

Parameters

  • svc string the named service of interest

Returns Promise<AgentID?> a promise which returns an AgentID that provides the service when resolved

agentsForService

Parameters

  • svc string the named service of interest

Returns Promise<Array<AgentID>> a promise which returns an array of AgentIDs that provides the service when resolved

agent

Gets a named AgentID for low-level access to UnetStack.

Parameters

Returns AgentID AgentID for the given name

host

Resolve node name to node address.

Parameters

  • nodeName string name of the node to resolve

Returns Promise<number?> address of the node, or null if unable to resolve

onParamChange

Registers a callback function to be called when a parameter value changes for the local node. This uses the ParamChangeNtf messages published by the Unet node to notify of parameter changes. The callback function will be called with the new value of the parameter.

Parameters

removeParamChange

Removes a callback function registered to be called when a parameter value changes for the local node.

Parameters

Protocol

Well-known protocol number assignments used in UnetStack

Type: Object<string, number>

UnetMessages

Well-known protocol Messages used in UnetStack

Type: Object<string, MessageClass>

toGps

Convert coordinates from a local coordinates to GPS coordinate

Parameters

  • origin Array Local coordinate system's origin as [latitude, longitude]
  • x Number X coordinate of the local coordinate to be converted
  • y Number Y coordinate of the local coordinate to be converted

Returns Array GPS coordinates (in decimal degrees) as [latitude, longitude]

toLocal

Convert coordinates from a GPS coordinates to local coordinate

Parameters

  • origin Array Local coordinate system's origin as [latitude, longitude]
  • lat Number Latitude of the GPS coordinate to be converted
  • lon Number Longitude of the GPS coordinate to be converted

Returns Array GPS coordinates (in decimal degrees) as [latitude, longitude]

DatagramReq

A message which requests the transmission of the datagram from the Unet

Type: Message

Properties

  • data Array<number> data as an Array of bytes
  • from number from/source node address
  • to number to/destination node address
  • protocol number protocol number to be used to send this Datagram
  • priority any priority assigned to the datagram request
  • reliability boolean true if Datagram should be reliable, false if unreliable
  • ttl number time-to-live for the datagram. Time-to-live is advisory, and an agent may choose it ignore it
  • route any route identifier to use when supported by the provider
  • mimeType string MIME type describing the payload
  • remoteRecipient any recipient identifier used by REMOTE service providers
  • mailbox string mailbox name used by REMOTE service providers
  • messageClass any application message class used by REMOTE service providers

DatagramNtf

Notification of received datagram message received by the Unet node.

Type: Message

Properties

  • data Array<number> data as an Array of bytes
  • from number from/source node address
  • to number to/destination node address
  • protocol number protocol number to be used to send this Datagram
  • ttl number time-to-live for the datagram. Time-to-live is advisory, and an agent may choose it ignore it

AgentID

An identifier for an agent or a topic.

Services

Services supported by fjage agents.

Performative

An action represented by a message.

MessageClass

Function to creates a unqualified message class based on a fully qualified name.