Listen to a diffrent network interface #1107
-
Lets say i have a server with 2 public ipv4 addresses. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
https://unetworking.github.io/uWebSockets.js/generated/interfaces/TemplatedApp.html#listen |
Beta Was this translation helpful? Give feedback.
-
To configure uWebSockets.js to listen on a specific IPv4 address, you need to specify the IP address in the App.listen() method. By default, uWebSockets.js listens on all available network interfaces (i.e., 0.0.0.0), but you can restrict it to listen on a specific IP. const uWS = require('uWebSockets.js');
const app = uWS.App();
// Define the specific IP address you want to listen on (replace with your desired IP)
const ipAddress = 'YOUR_SPECIFIC_IP'; // e.g., '192.168.1.100'
const port = 3000; // Define the port you want to listen on
app.get('/', (res, req) => {
res.end('Hello, this server is listening on a specific IP address!');
});
app.listen(ipAddress, port, (token) => {
if (token) {
console.log(`Listening on ${ipAddress}:${port}`);
} else {
console.log(`Failed to listen on ${ipAddress}:${port}`);
}
}); Replace YOUR_SPECIFIC_IP with the public IPv4 address you want uWebSockets.js to listen on. Explanation: |
Beta Was this translation helpful? Give feedback.
https://unetworking.github.io/uWebSockets.js/generated/interfaces/TemplatedApp.html#listen