Node.js server on local Natted network - javascript

I've developed a node.js application while I was in holiday and I was using a not natted wifi connection. Now that I'm back home with my natted wifi I'm not able to access my node js server through the localhost from my phone. I tried accessing it from the local IP but still my server didn't see any connection... Any suggestions?
I'm using socket connections with express and I'm using the 3000 port. I'm on arch linux.

Related

Getting ERR_CONNECTION_REFUSED on my node api called from angular app on remote device access

I have an Node App and an Angular App running on my System (LG Gram- Windows), and the node server is my API server and the angular App is consuming those APIs. The Angular server is served with --host 0.0.0.0 so that I can access the app through out my Local Network (WiFi). I tried to access the Angular app with my phone and other laptop (HP - Ubuntu), both the devices was able to access angular app, but the login call(Through the Angular APP) to node API from my phone is giving me an error, but the Ubuntu system is fine. I tried calling the Node API directly from both devices and was able to access it and got a response. The Ubuntu system had the same issue with login but it was somehow fixed. What could be the issue.
I have fixed the issue, Since both the Node and Angular server was running on the same machine, i have set the API url as http://localhost:4000/api which worked on the same laptop but not on my android device, which in fact is calling http://localhost:4000/api for the api calls, hence connection error (no server on port 4000 on my android device). When i changed the url to http://192.168.31.82:4000/api, my local network IP, it worked.

NodeJS - How to connect to remote PC that runs Node app?

I have a Nodejs client app, and a Nodejs server app. I use Apollo GraphQL for network.
These communicate fine if run on the same pc. They also work fine if the client is on another pc and server on my pc, over LAN only. They fail to communicate via internet.
My code that works right now:
server:
server.listen(PORT, '0.0.0.0',() ...
client:
const wsLink = new WebSocketLink({
uri: 'ws://192.168.10.41:8081/subscriptions',
Firs of all you must be sure that both nodes have a public IP, otherwise if you are behind a symmetric NAT you will not be able to do that.
After that you can use some of the modules of node, for example UDP(user datagram protocol) to try the connection.
Good Luck

phonegap doesn't connect with xampp server on localhost

I have a PhoneGap project on my windows 7 PC. I have installed the PhoneGap developer app on my PC which connects through server address: http://192.168.1.16:3000.
When I load the project on the PhoneGap developer app, everything works fine. The problem is that I have a database which is saved locally on my PC (localhost) and I access it through XAMPP. When I setup the XAMPP server I can not access the database and when I run the project it's showing me an error.
If I connect an online database on a server it works. I mean it's working with an online database but not working on localhost.
Can anyone help me how to access my database on localhost server.
var url = "http://localhost:81/myapp/auth.php";
And if i run open this link on above image result here:
enter image description here
Your app is running on the Phone and interprets localhost as its own host.
Try to use the IP you get from your Router of your PC smth. like 192.168.x.x or so.
Also be aware that direct connections to your PC-Database may be blocked because of the listen config of your MySQL Server

mosquitto 1.4.14 not supporting web socket in windows and code is not working

I am working mqtt and i made a webscript and i want to use it with mosquiito 1.4.14, but its not working with web socket support, I tried to put WEBSOCKET and port number in mosquitto.conf file but its still not working..
I had error WebSocket connection to 'ws://localhost:1883/mqtt' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED...
I checked my code by replacing the online broker address and port number it`s working... so where to find the web socket support broker or how to make mosquitto to work with web socket
The pre-built versions of mosquitto for Windows available for download from the mosquitto website do NOT include websocket support.
The only way to get websocket support on Windows with mosquitto is to build it yourself as described in this Internet of Things Stack Exchange post:
https://iot.stackexchange.com/questions/1205/how-to-enable-websockets-on-mosquitto-running-on-windows/

getting "websocket connection invalid" error using socket.io on an ec2 instance?

I have this web app written with express and socket.io using node.js, the app works brillantly on localhost, but when i push to my ec2 server, it connects for like 20 seconds then disconnects, and then connects again etc...
giving me the error on the node console as
warn - websocket connection invalid
info - transport end
SERVER
app = express()
server = http.createServer(app)
io = require('socket.io').listen(server)
CLIENT
socket = io.connect()
I know the problem is not with my code, because I fully tested the web app on localhost, so the only problem is where this code is running, which is my ec2 instance?
There could be many possible reasons you can get this error:
You are using browser that partially or does not support websockets. You can check if your browser supports websockets here.
Using proxy that does not support websocket. If there is some server(load balancer) between your client and your node server that does not support websocket.
You are using socket.io version 0.9.1/0.9.1-1. This behaviour is a reported bug for this version. So upgrade to latest socket.io version which is 0.9.14.
Browser connectivity is firewalled/blocked.
Code related problem.
Make sure you're using latest versions of node, express and socket.io on your ec2. Also, provide some data about currently used versions both on your local machine and on ec2 instance.
Running on your local machine you don't have to deal with network latency, NAT issues, or firewalls. Running on EC2 you have all of those.
Web Sockets are relatively new and unstable. So to begin with be sure you're running the latest versions (and let us know what they are). Perhaps the version of socket.io installed on your local machine is different than the version installed in your EC2 server.
If there is no activity during those 20 seconds before losing the connection, one possibility is that keep-alive is set too low.
See https://groups.google.com/forum/?fromgroups=#!topic/socket_io/RUv70BguZ-U for a similar problem. The solution there was to use heartbeat to keep the connection open.
A bit more on socket.io heartbeats if you're not already using them:
Advantage/disadvantage of using socketio heartbeats

Categories

Resources