• 5
  • 0

Ethereum Websockets Problems with NODE.JS on the Ubuntu server

As projects to build developers linked to blockchain, it may be necessary to connect to binanchers using Node.js. However, if they face problems like Errno: -111 | Code: 1006 Econdrefuded is a decisive solution to connection problems.

Understand the error code

Errno: -111 'indicates an error that occurred during the system system.

-Code: 1006 ECONDEFUDED ‘determines that the connection has been rejected by the server.

Steps of Ethereum websockets for node.js on the Ubuntu

server

Ethereum: My ubuntu server can’t connect to binance websockets with nodejs (errno: -111 | code: 1006 ECONNREFUSED)

Step 1: Install and define binance binockets

Before trying to connect, make sure you have installed Binance Websockets:

`Bash

Sudo Apt update

Sudo Apto installation Binance-Websocket-Clerk

'

Then define the connection to the Ethereum account:

Bash

Echo "username = your_ethereum_username" | Sudo Sed -i " / ^ Websocket_username / S / ^ \ (* \) / \ 1" / etc / bashrc

'

Replaceyour_ethereum_usernameusing your username Binance Websockets.

Step 2: Define the node.js environment

Make sure Node.js and NPM are installed:

Bash

Sudo Apt update

Sudo apt installation nodejs npm

'

Check the Node.js version by launching "node -v".

Step 3: Create a simple websocket connection in node.js

Create a new file called "server.js (or any other name) with the following code:

`Javascript

Const Websocket = require ('WS');

Const WSS = New Websocket.Server ({Port: 8080});

Wss.on ('connection', (ws) => {

Console.log ("Connected Client");

// Manage incoming customer data

Ws.on ('message', (message) => {

Console.log (message received from the customer: $ {message});

// Send the message received to all customers

Wss.clients.Foreach ((customer) => {

If (Customer! == WS && Customer.Readystate === Websocket.open) {

client.send (message);

}

});

});

// Manage disconnections

Ws.on ('close', () => {

Console.log ("disconnected client");

});

});

Console.log ("server launched on door 8080");

'

Step 4: Start the NODE.JS server

Start the server starting:

Bash

NODE SERVER.JS

'

Open the new terminal window and join your Binance web block with the WebSocket customer in Node.js using the following evening code (replaceyour_ethereum_username ‘using your real web -scientific username):

`Javascript

Const Websocket = require ('WS');

Const WSS = New Websocket.Server ({Port: 8080});

Wss.on ('connection', (ws) => {

Console.log ("Connected Client");

// Manage incoming customer data

Ws.on ('message', (message) => {

Console.log (message received from the customer: $ {message});

// Send the message received to all customers

Wss.clients.Foreach ((customer) => {

If (Customer! == WS && Customer.Readystate === Websocket.open) {

client.send (message);

}

});

});

// Manage disconnections

Ws.on ('close', () => {

Console.log ("disconnected client");

});

});

Console.log ("Successful Websocket Connection");

` ‘

Step 5: To solve connection problems

If you still have problems, make sure:

– The Binance Websockets username is correct.

– Your Ethereum account has a sufficient balance for gas costs to pay the WebSocket connection.

– Ubuntu Server has sufficient resources (CPU, memory and bandwidth) to process the WebSocket connection.

Conclusion

Problem solving with the connection of websockets in Node.js can be complex.

Add Comment

Your email address will not be published. Required fields are marked *