php – How to allow other networks to connect to server nodejs socket io-ThrowExceptions

Exception or error:

I am attempting to create a live chat using socket.io, currently I can only connect if I am using my own network. (Testing through [ngrok]https://ngrok.com/).

How can I allow others to also connect?

socket.js file:


var app = require('express')();
var http = require('http').createServer(app);
var io = require('socket.io')(http);


http.listen(3000, function(){
  console.log('listening on *:3000');
});


io.on('connection', function(socket){
  console.log('a user connected');

  socket.on('chat.message', function(message) {
    console.log(message)
     io.emit('chat.message', message)
  })
});

chat.js file:


import io from 'socket.io-client';

const socket = io('my_ipv4_address':3000');

var app = new Vue({
    el: '#app',
    mounted: function() {
      console.log('testing 123')
      socket.on('chat.message', function(message) {
        this.messages.push(message)
      }.bind(this));
    },
    data: {
      messages: [],
      message: null
    },
    methods: {
        send() {
            socket.emit('chat.message', this.message)
    }
}})

How to solve:

@jfriend00 solved the issue.

I also changed

const socket = io('my_ipv4_address':3000');

to

const socket = io('my_public_ip':3000');

Leave a Reply

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