NEQTO Docs
  • Languages iconEnglish
    • 日本語
  • Docs
  • API
  • FAQ

›neqto.js

Getting Started

  • NEQTO Hello World!
  • Tutorial Step 1. NEQTO Console Setting
  • Tutorial Step 2. Device Settings & Launching Service (NEQTO Bridge)
  • Tutorial Step 2. Device Settings & Launching Service (STM32 Discovery)
  • Tutorial Step 2. Device Settings & Launching Service (SPRESENSE)
  • Tutorial Step 3. Application development using scripts

NEQTO

  • NEQTO Account Registration
  • Sub-accounts
  • API Usage
  • NEQTO Engine Firmware List
  • Support Guidelines
  • For safe and secure use of the NEQTO products
  • Vulnerability Disclosure Policy

NEQTO Console

  • Introduction
  • Fundamentals
  • Administrative Actions
  • Device Management
  • Linux-based Device Management
  • Batch Registration
  • Scripts
  • Actions and Contacts
  • View Data from the Console
  • NEQTO Apps

    • About NEQTO Apps
    • NEQTO Infinitypool
    • NEQTO Insights
    • NEQTO Custodia
    • NEQTO Flow
  • Machine Driver
  • Recommended Browsers
  • Billing Information

SPRESENSE

    Hardware Specifications

    • 01. About Spresense

    Software Specifications

    • 01. Operational Flow
    • 02. Initial Installation
    • 03. Spresense Wi-Fi Initial Setup
    • 04. Spresense LTE-M Initial Setup
    • 05. Debug Log Acquisition
    • 06. System LED Indications
    • 07. Event Messages
    • 08. Updating Firmware

    neqto.js

    • 01. About neqto.js
    • 02. Log
    • 03. Timers
    • 04. HTTP
    • 05. HTTPS
    • 06. MQTT
    • 07. Secure
    • 08. Storage
    • 09. Sleep
    • 10. RTC
    • 11. GPIO
    • 12. UART
    • 13. SPI
    • 14. I2C
    • 15. ADC
    • 16. GNSS
    • 17. Camera
    • 18. Utils
    • 19. nqSpresense
    • 20. nqService
    • 21. nqMqtt
    • 22. nqFOTA
    • 23. nqWiFi
    • 24. nqLte

STM32 Discovery

    Hardware Specifications

    • 01. About STM32 Discovery Kit (B-L4S5I-IOT01A)

    Software Specifications

    • 01. Operational Flow
    • 02. Initial Installation
    • 03. STM32 Discovery Wi-Fi Initial Setup
    • 04. Debug Log Acquisition
    • 05. System LED Indications
    • 06. Event Messages
    • 07. Updating Firmware

    neqto.js

    • 01. About neqto.js
    • 02. Log
    • 03. Timers
    • 04. HTTP
    • 05. HTTPS
    • 06. MQTT
    • 07. Secure
    • 08. Storage
    • 09. Sleep
    • 10. RTC
    • 11. UserSW
    • 12. GPIO
    • 13. UART
    • 14. SPI
    • 15. I2C
    • 16. ADC
    • 18. Utils
    • 19. nqDiscovery
    • 20. nqService
    • 21. nqMqtt
    • 22. nqFOTA
    • 23. nqWiFi

NEQTO Bridge

    Hardware Specifications

    • 01. NEQTO Bridge Module
    • 02. NEQTO Bridge Wi-Fi Module
    • 03. NEQTO Bridge LTE-1 Module
    • 04. NEQTO Bridge LTE-M/NB Module
    • 05. NEQTO Bridge IO Board
    • 06. NEQTO Bridge Digital IO Board
    • 07. NEQTO Bridge Connector Board

    Software Specifications

    • 01. Operational Flow
    • 02. NEQTO Bridge Wi-Fi Module Initial Setup
    • 03. NEQTO Bridge LTE Module Initial Setup
    • 04. Debug Log Acquisition
    • 05. System LED Indications
    • 06. Event Messages
    • 07. Updating Firmware

    neqto.js

    • 01. About neqto.js
    • 02. Log
    • 03. Timers
    • 04. HTTP
    • 05. HTTPS
    • 06. MQTT
    • 07. Secure
    • 08. Storage
    • 09. Sleep
    • 10. RTC
    • 11. UserSW
    • 12. GPIO
    • 13. UART
    • 14. SPI
    • 15. I2C
    • 16. ADC
    • 17. BLE
    • 18. Utils
    • 19. nqBridge
    • 20. nqService
    • 21. nqMqtt
    • 22. nqFOTA
    • 23. nqWiFi
    • 24. nqLte
    • 25. nqLAN
    • 26. nqEx

Linux-based device

    Software Specifications

    • 01. System Requirements
    • 02. Installation
    • 03. Software Configurations
    • 04. Operational Flow
    • 05. Debug Log Acquisition
    • 06. Event Messages
    • 07. Updating Software

    neqto.js

    • 01. About neqto.js
    • 02. Log
    • 03. Timers
    • 04. HTTP
    • 05. HTTPS
    • 06. MQTT
    • 07. Secure
    • 08. Storage
    • 09. RTC
    • 10. UNIXSocket
    • 11. FileSystem
    • 12. SubProcess
    • 13. SubTask
    • 14. Queue
    • 15. Utils
    • 16. nqLinux
    • 17. nqService
    • 18. nqMqtt
    • 19. nqFOTA
    • 20. nqLAN

neqto.js Libraries

  • About neqto.js Libraries
  • UART

    • GM65 Barcode Reader
    • SRF Ultrasonic Range Finder - Serial Mode

    I2C

    • HTS221 v2 Temperature and Humidity Sensor
    • LIS2DW12 v2 Accelerometer
    • SRF Ultrasonic Range Finder - I2C Mode
    • [Archive] HTS221 Temperature and Humidity Sensor
    • [Archive] LIS2DW12 Accelerometer

    Utils

    • RTC Alarm Synchronized Scheduler

    Integration

    • AWS S3 v2
    • AWS IoT Core v2
    • Azure IoT v2
    • [Archive] GCP IoT Core
    • [Archive] AWS S3
    • [Archive] AWS IoT Core

neqto.js Snippets

  • About neqto.js Snippets
  • DataDog
  • Dropbox
  • Google Sheets
  • InfluxDB
  • Oracle Cloud Object Storage
  • Salesforce
  • Splunk
  • Niagara
  • [Archive] SAP Cloud Platform Internet of Things

Release Notes

  • NEQTO Console Updates
  • NEQTO Firmware (Bridge Wi-Fi/LTE Module) Releases
  • NEQTO Firmware (STM32 Discovery Wi-Fi) Releases
  • NEQTO Firmware (Spresense Wi-Fi/LTE-M) Releases
  • NEQTO Engine for Linux Releases
  • neqto.js Libraries Releases

10. UNIXSocket

The unixsocket object is a built-in object that provides process communication functions between external applications using UNIX domain sockets.

Functional overview:

  • Provides the UNIX socket server function.
  • Provides the UNIX socket client function.
  • The socket type is SOCK_STREAM (Stream Oriented).
  • Any path name can be specified. Abstract socket addresses are also available.

Limitations:

  • The number of UNIX socket resources that can be used is 3.
  • The maximum number of clients that can connect to a UNIX socket server is 3.



unixsocket Global Object

Methods()/PropertiesSummaryVersionNote
unixsocket.create()Create a UNIX socket instance.



Details

unixsocket.create(mode,path[,options])

Create a UNIX socket instance.

NameTypeM/OSummaryNote
modestringmandatorySpecify 'server' or 'client'.
pathstringmandatorySpecify the socket path.
Ex) /tmp/test.unixsocket
To specify an abstract socket address, insert '@' at the beginning of the path.
Ex) @/tmp/test.unixsocket
optionsObjectoptionalOptions
Refer to Options for details.
return{Server}, {Client}, null-{Server} : Generated {Server}
{Client} : Generated {Client}
null : If instance creation fails due to lack of resources, if an instance of the specified path has already been created (at server), or if the specified path does not exist (at client)

Options

NameTypeM/OSummaryNote
recvBuffSizenumberoptionalReceive buffer size [Byte]
Range: 1 - 2,147,483,647
The default value is 4096.



{Server}

Methods()/PropertiesSummaryVersionNote
.on()Registers an event handler.
.listen()Starts waiting for the socket connection from the client.
.read()Reads data received from the client.
.write()Sends data to the client.
.isConnected()Gets the connection status of the socket.
.close()Disconnects the socket.
.release()Releases a server resource.



Details

.on(event,callback)

Registers an event handler.

NameTypeM/OSummaryNote
eventstringmandatoryEvent name
Names that can be used are: accept, readable, close
callback()functionmandatoryExecutes callback processing when an event occurs.
returnundefined--If the parameter is abnormal, an exception occurs.

event : ’accept’

Executes callback processing when a client connects to the socket.

ArgumentsTypeSummaryNote
indexnumberAssigned client index

event : ’readable’

Executes callback processing if data exists in the socket receive buffer.

ArgumentsTypeSummaryNote
indexnumberClient index where event occurred

event : ’close’

Executes callback processing when a socket disconnection occurs.

Note that if the client disconnects the socket while data is still in the socket receive buffer, the callback process will not be executed immediately. It is necessary to read all data with the .read() method.

ArgumentsTypeSummaryNote
indexnumberClient index where event occurred

.listen()

Starts waiting for the socket connection from the client.

This method executes only once after the instance is created.
Thereafter, a client management number (Client index) is assigned each time a client connects. The client index can be found using the 'accept' event notification or the .isConnected() method. This index will be one of the range 0 to "Maximum number of client connections - 1".

NameTypeM/OSummaryNote
returnboolean-true: Success
false: Failure

.read(index[,isBin])

Reads data received from the client.

NameTypeM/OSummaryNote
indexnumbermandatorySpecify the target client index.
isBinbooleanoptionalSpecify the readout data format.
true: Readout in binary data format
false: Readout in string format
The default value is false.
returnArrayBuffer, string-Readout data
The return type is determined by isBin.
If isBin is true, the type is ArrayBuffer; otherwise, the type is string.
The readout data will be less than or equal to the size specified by recvBuffSize. If there is no readout data, the size will be 0.
If the parameter is abnormal, an exception occurs.

.write(index,data)

Sends data to the client.

NameTypeM/OSummaryNote
indexnumbermandatorySpecify the target client index.
datastring, ArrayBuffermandatorySent data
returnnumber-Sent data size
If the sending fails, -1 is returned.
If the parameter is abnormal, an exception occurs.

.isConnected(index)

Gets the connection status of the socket.

NameTypeM/OSummary                                        Note
indexnumbermandatorySpecify the target client index.
returnboolean-Socket connection state
true: Socket connected
false: Socket not connected
If the parameter is abnormal, an exception occurs.

.close(index)

Disconnects the socket.

NameTypeM/OSummary                                        Note
indexnumbermandatorySpecify the target client index.
returnundefined--If the parameter is abnormal, an exception occurs.

.release()

Releases a server resource.
All sockets while connected will be disconnected.

NameTypeM/OSummaryNote
returnundefined--



{Client}

Methods()/PropertiesSummaryVersionNote
.on()Registers an event handler.
.connect()Connects a socket to the server.
.read()Reads data received from the server.
.write()Send data to the server.
.isConnected()Gets the connection status of the socket.
.close()Disconnects the socket.
.release()Releases a client resource.



Details

.on(event,callback)

Registers an event handler.

NameTypeM/OSummaryNote
eventstringmandatoryEvent name
Names that can be used are: connect, readable, close
callback()functionmandatoryExecutes callback processing when an event occurs.
returnundefined--If the parameter is abnormal, an exception occurs.

event : ’connect’

Executes callback processing when a socket is connected.

event : ’readable’

Executes callback processing if data exists in the socket receive buffer.

event : ’close’

Executes callback processing when a socket disconnection occurs.
To reconnect, the .connect() method must be executed.

Note that if the server disconnects the socket while data is still in the socket receive buffer, the callback process will not be executed immediately. It is necessary to read all data with the .read() method.

.connect()

Connects a socket to the server.

NameTypeM/OSummaryNote
returnboolean-true: Success
false: Failure

.read([isBin])

Reads data received from the server.

NameTypeM/OSummaryNote
isBinbooleanoptionalSpecify the readout data format.
true: Readout in binary data format
false: Readout in string format
The default value is false.
returnArrayBuffer, string-Readout data
The return type is determined by isBin.
If isBin is true, the type is ArrayBuffer; otherwise, the type is string.
The readout data will be less than or equal to the size specified by recvBuffSize. If there is no readout data, the size will be 0.
If the parameter is abnormal, an exception occurs.

.write(data)

Send data to the server.

NameTypeM/OSummaryNote
datastring, ArrayBuffermandatorySent data
returnnumber-Sent data size
If the sending fails, -1 is returned.
If the parameter is abnormal, an exception occurs.

.isConnected()

Gets the connection status of the socket.

NameTypeM/OSummaryNote
returnboolean-Socket connection state
true: Socket connected
false: Socket not connected

.close()

Disconnects the socket.
To reconnect, the .connect() method must be executed.

NameTypeM/OSummaryNote
returnundefined--

.release()

Releases a client resource.
A socket while connected will be disconnected.

NameTypeM/OSummaryNote
returnundefined--



Object Usage Examples

Sample 1

This is a sample of UNIX Socket Server.
Receives data from the client and sends it loopback.

//The maximum number of clients that can connect to a UNIX socket server is 3
var readEvt = [false,false,false];

var path ='/tmp/test.unixsocket'
var server = unixsocket.create('server', path);
if(!server) throw new Error('Failed to create server instance');

server.on('accept', function(index) {
    print('accept', index);
});
server.on('readable', function(index) {
    print('readable', index);
    readEvt[index] = true;
});
server.on('close', function(index) {
    print('close', index);
});

if(!server.listen()) throw new Error('Failed to start server listening'); 

print('Server listening started! [' + path + ']');

while(1) {
    for(var i=0; i<readEvt.length; i++) {
        if(readEvt[i]) {
            readEvt[i] = false;
            var rStr = server.read(i);
            print('recv ' + i + ': ' + rStr.replace(/[\x00-\x1F\x7F-\x9F]/g,'\\') + ' (' + rStr.length + ')');
             //Loopback
            if(server.write(i, rStr) == rStr.length) {
                print('send ' + i + ': OK');
            }
        }
    }
}

Sample 2

This is a sample of UNIX socket client.
While connected to the server, data will be sent in 1-second cycles. It also constantly waits for incoming data from the server.

var path ='/tmp/test.unixsocket'
var client = unixsocket.create('client', path);
if(!client) throw new Error('Failed to create client instance');

client.on('connect', function() {
    print('connect');
});
client.on('readable', function() {
    print('readable');
});
client.on('close', function() {
    print('close');
});

var sendEvt = false;
var tmobj = setInterval(function() { sendEvt = true; }, 1000);

while(1) {
    if(!client.isConnected()) {
        print('Connecting... [' + path + ']');
        if(!client.connect()) {
            setTimeout(1000).wait(); //1sec wait
        }
    } else {
        if(sendEvt) {
            sendEvt = false;
            var sStr = Date.now() + ' to server\n';
            if(client.write(sStr) == sStr.length) {
                print('send: OK');
            }
        }
        var rStr = client.read();
        if(rStr.length) {
            print('recv: ' + rStr.replace(/[\x00-\x1F\x7F-\x9F]/g,'\\') + ' (' + rStr.length + ')');
        }
    }
}



Updated: 2022-10-25
← 09. RTC11. FileSystem →
  • unixsocket Global Object
  • Details
    • unixsocket.create(mode,path[,options])
    • Options
  • {Server}
  • Details
    • .on(event,callback)
    • event : ’accept’
    • event : ’readable’
    • event : ’close’
    • .listen()
    • .read(index[,isBin])
    • .write(index,data)
    • .isConnected(index)
    • .close(index)
    • .release()
  • {Client}
  • Details
    • .on(event,callback)
    • event : ’connect’
    • event : ’readable’
    • event : ’close’
    • .connect()
    • .read([isBin])
    • .write(data)
    • .isConnected()
    • .close()
    • .release()
  • Object Usage Examples
    • Sample 1
    • Sample 2
AboutNewsProductsFAQPrivacy PolicyVulnerability Disclosure Policy
NEQTO Console
IntroductionFundamentalsAdministrative ActionsDevice Management NEQTO Apps
NEQTO Bridge
NEQTO Bridge ModuleNEQTO Bridge Wi-Fi ModuleNEQTO Bridge LTE-1 ModuleError Logging Event Messages
API Documentation
API UsageGlobal APIRegional APIAPI Terms of Service
Jigsaw, Inc.
© 2025 JIG-SAW INC.