0

The server app was running quite fine on Heroku but after migrating to Azure the server would not just start.

Here is the code..


const PORT = process.env.PORT || 2498;
const INDEX = '/index.html';

const server = express()
  .use((req, res) => res.sendFile(INDEX, { root: __dirname }))
  .listen(PORT, () => console.log(`We\'re live on channel : ${PORT}`));

const wss = new Server({ server });

wss.on('connection', (ws) => {
  console.log('Client connected');

  ws.on('close', () => console.log('Client disconnected'));

  ws.on('message', (message) =>{
    // this stays within the server
    console.log('[SERVER]: Received a message => %s', message );

})

})```

.........


Clients connected are returning not establish an handshake ....
Ayshuser
  • 31
  • 9

1 Answers1

0

Azure web app only supports the exposure of port 80 and 443 for website access.

My previous requirements and test results:

I think your problem is a typical problem. I also had related requirements before, and the test failed in the webapp. All documents of Azure app service, talking about websocket, all use SignalR. I also tested the signalr service and it was successful, but this service is free and currently only supports 20 client connections.

What I thought before was to create a console program and put it in webjob to let webjob provide websocket service, but it all failed in the end.

Because azure webapp runs in a sandbox environment, and only open ports 80 and 443, we can't do more configuration. Obviously, the port that your websocket service starts is 2498, so it is not supported.

Suggestion

If you must use websocket, regardless of programming language, you must support custom port opening, such as using Virtual Machine.

You can compare the charges of azure cloud service and virtaul machine. Which one is right for you and which one to use.

Another suggestion is that you can buy a third-party intranet penetration tool and use a fixed IP or URL, such as ngrok, so that you can put the websocket service on your company's internal server. (The test is valid).

Of these three options, intranet penetration may be the most cost-effective choice. You can choose according to your needs.

Jason Pan
  • 15,263
  • 1
  • 14
  • 29