简体   繁体   中英

Socket server with Node.js and Cloud9 IDE

I am totally new to Cloud9 IDE, so my question amy be silly, but i can't find answer in docs. I want to make client - server application with Node.js + MongoDB as socket server, and client - desktop application which I debug and run on my machine (Cloud9 IDE doesn't support language on which I write it). Looking at Cloud9 IDE I've found it very nice for developing server-side part of my application and may be as hosting solution. But I can't find how to make socket connection from client. For this I need to know IP adress or domain address of my server (I suppose it looks like " https://socialcrm-c9-painkkkiller.c9.io ") and port number. In docs I've found about "use process.env.PORT as the port and process.env.IP as the host in your scripts!" but to connect to server I need they real values! Commands console.log(process.env.PORT) and console.log(process.env.IP) gives me just "8080" and 0.0.0.0 Using " https://socialcrm-c9-painkkkiller.c9.io " as domain and 8080 as port gives me socket error. So is it possible at all? And if possible how to do it?

Cloud9 forwards port 80 of https://socialcrm-c9-painkkkiller.c9.io to port 8080 in your container. So there is no need to specify the port.

We do also support web sockets and they work in the same way. There's no need to specify another port.

The only thing you need to do is to make sure you are using the environment variables to connect to the right $IP and $PORT when starting your back-end process.

Old question - but I'm struggling with a similar problem. I don't have reputation to add a comment, but this should answer your question about getting the IP into your Cloud9 application.

You can reference process.env.IP to grab the IP... and fwiw, you can reference process.env.PORT to get the port.

Taken from: https://community.c9.io/t/writing-a-node-js-app/1731

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