Quantcast
Channel: Active questions tagged https - Stack Overflow
Viewing all articles
Browse latest Browse all 1854

Secured local WebSocket (WSS) works on PC but fails on mobile in LAN

$
0
0

I'm developing a Node.js application that uses a secure WebSocket (WSS) server for local network communication. The WebSocket connection works perfectly on the same PC where the server is running, but when I try to connect from a mobile device on the same network, I encounter a connection error.

const https = require('https');const fs = require('fs');const WS = require('ws');const IP = require('./IP.js');this.port = port;this.localIp = IP.getLocalIp();const serverOptions = {  key: fs.readFileSync(path.resolve(__dirname, 'key.pem')),  cert: fs.readFileSync(path.resolve(__dirname, 'cert.pem')),};this.server = https.createServer(serverOptions);this.wss = new WS.Server({ server: this.server });this.server.listen(this.port, this.localIp);

The IP.js file to get the local IP address:

const os = require('os');class IP {  constructor(ip) {    this.ip = ip;  }  static getLocalIp() {    const interfaces = os.networkInterfaces();    let localIp = "";    for (const iface in interfaces) {      for (const alias of interfaces[iface]) {        if (alias.family === "IPv4" && !alias.internal) {          localIp = alias.address;        }      }    }    if (!localIp) {      throw new Error("Local IP address not found.");    }    return localIp;  }}

Initially, I had a regular WebSocket (WS) server, and everything worked perfectly on both PC and mobile devices. When I transitioned to using wss, the connection started failing on the mobile device, though it still works on the PC. I need to ensure that the WebSocket server is accessible the same way from all devices on the LAN.

What could be causing the connection failure on the mobile device, and how can I ensure that the mobile device can successfully connect to the secured WebSocket server on the same network?


Viewing all articles
Browse latest Browse all 1854

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>