简体   繁体   中英

How to communicate with the nodeJS server setup in the Google cloud virtual machines(Windows server) through internet?

I am developing a chat app in android using soocket.io. This app need to communicate with one of the nodejs application listening at port 4000 in my Google cloud Virtual machine through internet. GCP provided internal and external IP. when I running the internalIP:4000 in browser of VM, I can see it is running fine. But in out side VM, when I run ExternalIP:4000 it is giving error. I dont know why it is not working.

So you already established that your service is running fine and is on a correct port (4000).

Now you have to expose to the Internet. By default this port is blocked for any traffic by GCP's Firewall . This way only ports for SSH, RDP or ICMP protocols are open to be able to connect to your VM's. If you need non-standard port you have to create apropriate firewall rule.

You can create it by running using Cloud Shell or running this in your VM's command prompt:

gcloud compute --project=my-project-name firewall-rules create my-app-port \
--direction=INGRESS --priority=1000 --network=default \
--action=ALLOW --rules=tcp:4000 --source-ranges=0.0.0.0/0 \
--target-tags=my-app-server

or create it using Cloud Console . Have a look at the documentation if you have any doubts.

In my example I used my-app-server network tag. You need to add it to your VM that runs the app server - otherwise the rule won't work. It's best to do it this way since you're only exposing one additional port on a single VM which is safest possible solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM