Difficulties connecting to socket.io server with Ionic - node.js

An overview of my setup:
A socket.io/node server is being hosted/ran on a computer in my local network.
An Ionic app is attempting to connect to the socket.io/node server to send/receive messages.
If I run the app in the browser with 'ionic serve', I am able to connect to the socket.io/node server successfully.
If I run the app in the emulator or on my device, I am only able to connect to the socket.io/node server if I add the -l (livereload) flag (ionic run android -l).
Originally, I hosted the node server on a heroku instance. I had no troubles connecting with this setup from browser, phone, or emulator. I had to switch to running the node server on a local computer so I have access to a local database.
Any ideas what is going on?

I fixed it by adding 'http://' to the beginning of the connection string.
Not sure why Ionic's livereload enabled me to connect without the 'http'

Related

connect node app running in windows to redis running in wsl

i have setup wsl in my windows server machine and started the redis service there.
from the windows command prompt i can use wsl redis-cli and run the redis commands.
but my node application is not able to detect the redis inside wsl. i am using redis in my node project.
is there any third party module i need to add to able to connect, this answer showed to add it in python.
the wsl's redis port was readily available.
const client = redis.createClient(); just kept the createClient() config blank and it connected.

My Ionic app can't access my local Node server from Android emulator

I'm trying to run for the first time my React/Ionic app on an Android Emulator using Capacitor. The app should connect to my local Node server using Axios.
While my app started successfully on the emulator, all server requests failed with Msg: Error: Network Error
Here's the steps that I did:
I configured Axios to connect to http://10.0.2.2:3001 instead of localhost, but the requests still fail
I opened the url http://10.0.2.2:3001/api in the Android Emulator Chrome browser, and it succeeded in connecting to my server and returning a response
I tried adding to my capacitor.config.json file the following conf, but my app still fails
"server": {
"allowNavigation": ["10.0.2.2"]
}
Would you have other advices I should try to make my app connect to my local server? Thank you
After searching, I found the solution in another SO question :
The problem comes from the fact the my app uses http instead of https requests which Android forbids by default, starting with API level 28.
To allow http requests, I added android:usesCleartextTraffic="true" to my app's AndroidManifest.xml
Reference: https://developer.android.com/guide/topics/manifest/application-element#usesCleartextTraffic
if you use instances on cloud, modify host file, on linux the rute is : /etc/hosts
add this line:
localhost < ip-public-your-instance >

NodeJS and React - LAN connection not working

Description
I have a Node server and React App running on my notebook Ubuntu 18.04.
Notebook ip is 10.0.0.101
I tried to connect my desktop to this server on the same network
Desktop ip is 10.0.0.100
Node is running on PORT=3333
React is running on PORT=3000
I can ping my notebook from my desktop but when I try to connect to node using Insomnia or to http://10.0.0.101:3000 from my desktop I cannot reach.
Errors
When try to connect to backend with Insomnia
Error: Couldn't connect to server
When try to connect to app on 10.0.0.101:3000
ERR_CONNECTION_TIMED_OUT
What I've done
I already changed the node listen and specified the port and the ip but it didn't work.
I tried to use my phone as router and connect from my phone to react on my notebook and also didn't work.
I've tried so many things since I can't remember them all.
I'm also creating a react-native app and when I try to connect to my mobile using Expo, it just works using tunnel, but cannot get data from the backend.
Please save me.
Thanks
After making many failed attempts, I realized that the problem was in my notebook.
I checked my firewall and it was disabled and still cannot get acess to my notebook on LAN. But finally I discovered what have to be done
Solution
You have to open the specific port for TCP traffic
Ubuntu:
sudo ufw allow <PORT-NUMBER>/tcp
or for Red Hat Enterprise
firewall-cmd --add-port <PORT-NUMER>/tcp
Reference: Examples of how to open firewall ports

How do I run Node Js on my VPS server

I write my server file with node.js and has successfully test in my local , i install node.js and mongoDB plugin on my server , that is windows, but when i type server url instead of my ip in my android app I can't find server and get error server not found
Please help me

nodejs http-server, can't connect localhost

I am using nodejs http-server for a web application. I am able to launch the http-server by running nom start. I can access my server through http://127.0.0.1:8080 but I can't connect by http://localhost:8080. I have checked that localhost can be ping from my terminal and localhost works fine with other server such as tomcat. So I think the problem relates to http-server only. Is there any configuration I need to setup on my application in order to support localhost access?

Resources