Tuesday 20 October 2020

cant connect to node server via socket.io after mapping ip:port address to a domain withouth port

im very new to nodejs so bare with me

so i have a nodejs server which i use to inject live data to my php/laravel website via socket.io i run my nodejs server in port 3001 and apache is using port 80

so my node server is running on

http://78.47.222.225:3001

so i noticed clients who use vpn or proxy cant connect to my nodeserver address and websocket connection fails for them

after asking in this question it was suggested its bcuz vpn is fire walling unusual ports

nodejs server doesn't respond when clients use vpn or proxy

so i maped a address to 3001 port , so basically

http://bia2roll.com/server ---proxying---> http://78.47.222.225:3001

so now when i go to http://bia2roll.com/server i get

Cannot GET /

which means its working but in my homepage http://bia2roll.com when i try to connect to the server via socket.io it fails ... homepage source

<html>
<head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.js" ></script>

</head>
<body>
<script>

    const  socket = io.connect("http://bia2roll.com/server" ,  {transports:['websocket']});

    socket.on('connect', function () {
        
        console.log('connected!!!') ; 
        
    });

</script>

</body>
</html>

not sure why is this happening but in my console i see it trying to connect to this address

WebSocket connection to 'ws://bia2roll.com/socket.io/?EIO=3&transport=websocket' failed: Error during WebSocket handshake: Unexpected response code: 301
r.doOpen @ index.js:83

but shouldn't it try the bia2roll.com/server/socket.io ? considering i gave http://bia2roll.com/server to io.connect ?

it works fine when i try connecting via ip:port ... try this address to connect via ip:port instead of proxy address

http://bia2roll.com?port=1



from cant connect to node server via socket.io after mapping ip:port address to a domain withouth port

No comments:

Post a Comment