- UnetSocket
- Parameters
- Examples
- close
- isClosed
- bind
- unbind
- isBound
- connect
- disconnect
- isConnected
- getLocalAddress
- getLocalProtocol
- getRemoteAddress
- getRemoteProtocol
- setTimeout
- getTimeout
- setTTL
- getTTL
- setPriority
- getPriority
- setReliability
- getReliability
- setRoute
- getRoute
- setMimeType
- getMimeType
- setRemoteRecipient
- getRemoteRecipient
- setMailbox
- getMailbox
- setMessageClass
- getMessageClass
- setServiceProvider
- getServiceProvider
- setSendMode
- getSendMode
- send
- receive
- getGateway
- agentForService
- agentsForService
- agent
- host
- onParamChange
- removeParamChange
- Protocol
- UnetMessages
- toGps
- toLocal
- DatagramReq
- DatagramNtf
- AgentID
- Services
- Performative
- MessageClass
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.
hostnamestring? hostname/ip address of the master container to connect toportstring? port number of the master container to connect topathstring path of the master container to connect to (for WebSockets) (optional, default'')
let socket = await new UnetSocket('localhost', 8081, '/ws/');Returns Promise<UnetSocket> Promise which resolves to the UnetSocket object being constructed
Closes the socket. The socket functionality may not longer be accessed after this method is called.
Returns void
Checks if a socket is closed.
Returns boolean true if closed, false if open
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
protocolProtocol protocol number to listen for
Returns boolean true on success, false on failure
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
Checks if a socket is bound.
Returns boolean true if bound to a protocol, false if unbound
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.
Returns boolean true on success, false on failure
Resets the default destination address to undefined, and the default protocol number to Protocol.DATA.
Returns void
Checks if a socket is connected, i.e., has a default destination address and protocol number.
Returns boolean true if connected, false otherwise
Gets the local node address of the Unet node connected to.
Returns Promise<int> local node address, or -1 on error
Gets the protocol number that the socket is bound to.
Returns number protocol number if socket is bound, -1 otherwise
Gets the default destination node address for a connected socket.
Returns number default destination node address if connected, -1 otherwise
Gets the default transmission protocol number.
Returns number default protocol number used to transmit a datagram
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.
msnumber timeout in milliseconds
Returns void
Gets the timeout for datagram reception.
Returns number timeout in milliseconds
Sets the default time-to-live for datagrams sent using this socket. TTL is advisory; an agent may choose to ignore it.
ttlnumber time-to-live in seconds
Returns void
Gets the default time-to-live for datagrams sent using this socket.
Returns number time-to-live in seconds, or NaN if not set
Sets the default priority for datagrams sent using this socket.
priorityany priority value; interpretation is provider-dependent
Returns void
Gets the default priority for datagrams sent using this socket.
Returns any priority value, or null if not set
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.
reliabilityboolean true for reliable delivery, false for unreliable
Returns void
Gets the default reliability setting for datagrams sent using this socket.
Returns (boolean | null) true if reliable, false if unreliable, null if not set
Sets the default route identifier for datagrams sent using this socket. Route selection is provider-dependent; not all providers support explicit routing.
routeany route identifier
Returns void
Gets the default route identifier for datagrams sent using this socket.
Returns any route identifier, or null if not set
Sets the default MIME type describing the datagram payload. This can be used by REMOTE service providers to apply content-aware compression.
mimeTypestring MIME type string (e.g. 'application/json')
Returns void
Gets the default MIME type for datagrams sent using this socket.
Returns (string | null) MIME type string, or null if not set
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.
remoteRecipientany remote recipient identifier (e.g. an AgentID or name string)
Returns void
Gets the default remote recipient for datagrams sent using this socket.
Returns any remote recipient identifier, or null if not set
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.
mailboxstring mailbox name
Returns void
Gets the default mailbox name for datagrams sent using this socket.
Returns (string | null) mailbox name, or null if not set
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.
messageClassstring fully-qualified message class name (e.g. 'org.example.Status')
Returns void
Gets the default application message class for datagrams sent using this socket.
Returns (string | null) message class name, or null if not set
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.
Returns void
Gets the currently configured service provider override.
Returns (AgentID | null) the override agent id, or null if auto-selection is active
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.
sendModenumber one of UnetSocket.NON_BLOCKING, SEMI_BLOCKING, or BLOCKING
Returns void
Gets the current send mode.
Returns number current send mode (NON_BLOCKING=0, SEMI_BLOCKING=1, BLOCKING=2)
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.
data(Array<number> | DatagramReq) data to be sent over the socket as an Array of bytes or DatagramReqtonumber destination node address (optional, defaultthis._remoteAddress)protocolnumber protocol number (optional, defaultthis._remoteProtocol)
Returns Promise<boolean> true if the Unet node agreed to send out the Datagram, false otherwise
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
Gets a Gateway to provide low-level access to UnetStack.
Returns Gateway underlying fjage Gateway supporting this socket
Gets an AgentID providing a specified service for low-level access to UnetStack
svcstring the named service of interest
Returns Promise<AgentID?> a promise which returns an AgentID that provides the service when resolved
svcstring the named service of interest
Returns Promise<Array<AgentID>> a promise which returns an array of AgentIDs that provides the service when resolved
Gets a named AgentID for low-level access to UnetStack.
namestring name of agent
Returns AgentID AgentID for the given name
Resolve node name to node address.
nodeNamestring name of the node to resolve
Returns Promise<number?> address of the node, or null if unable to resolve
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.
Removes a callback function registered to be called when a parameter value changes for the local node.
Well-known protocol number assignments used in UnetStack
Well-known protocol Messages used in UnetStack
Type: Object<string, MessageClass>
Convert coordinates from a local coordinates to GPS coordinate
originArray Local coordinate system's origin as[latitude, longitude]xNumber X coordinate of the local coordinate to be convertedyNumber Y coordinate of the local coordinate to be converted
Returns Array GPS coordinates (in decimal degrees) as [latitude, longitude]
Convert coordinates from a GPS coordinates to local coordinate
originArray Local coordinate system's origin as[latitude, longitude]latNumber Latitude of the GPS coordinate to be convertedlonNumber Longitude of the GPS coordinate to be converted
Returns Array GPS coordinates (in decimal degrees) as [latitude, longitude]
A message which requests the transmission of the datagram from the Unet
Type: Message
dataArray<number> data as an Array of bytesfromnumber from/source node addresstonumber to/destination node addressprotocolnumber protocol number to be used to send this Datagrampriorityany priority assigned to the datagram requestreliabilityboolean true if Datagram should be reliable, false if unreliablettlnumber time-to-live for the datagram. Time-to-live is advisory, and an agent may choose it ignore itrouteany route identifier to use when supported by the providermimeTypestring MIME type describing the payloadremoteRecipientany recipient identifier used by REMOTE service providersmailboxstring mailbox name used by REMOTE service providersmessageClassany application message class used by REMOTE service providers
Notification of received datagram message received by the Unet node.
Type: Message
dataArray<number> data as an Array of bytesfromnumber from/source node addresstonumber to/destination node addressprotocolnumber protocol number to be used to send this Datagramttlnumber time-to-live for the datagram. Time-to-live is advisory, and an agent may choose it ignore it
An identifier for an agent or a topic.
Services supported by fjage agents.
An action represented by a message.
Function to creates a unqualified message class based on a fully qualified name.