问题
I'm trying to get a nodejs socket server running that will allow remote communication between two clients running a Flash game that communicates using a custom protocol. Due to Flash security restrictions, it seems that the socket server must be running on the same host as the web server that servers the Flash game. I've been continuously getting the following error:
The service crashed at startup or is listening to the wrong port. It failed to respond on port "nodejs" (8080) within 30 seconds
What I need is a way to run my nodeJS server code, while simultaneously serve the flash files.
I'm using the environment JSON variables to determine what port to listen on, and my YML is similar to the one discussed here but no luck... Just wondering if I can get some info on how to create a working socket server/web server that will work for this (or if it is actually possible)
回答1:
You can use the following dotcloud.yml
file:
www:
type: nodejs
ports:
mything: tcp
Then in your Node.js app, you can bind a HTTP server to port 8080, and an arbitrary TCP server to the port contained by environment variable $PORT_MYTHING
. Then run dotcloud info
on your service; in the ports
section, you will see something like this:
- name: mything
url: tcp://myapp-johndoe.dotcloud.com:12345
From now on, if you connect to myapp-johndoe.dotcloud.com
on port 12345
, you will actually connect to $PORT_MYTHING
in your application.
I hope that it makes sense, and that it is what you were looking for!
来源:https://stackoverflow.com/questions/12065217/dotcloud-www-and-tcp-in-single-app