title: How to declare ports in Cloud9 using Python
body: <p>I'm new to using <a href="http://c9.io" rel="noreferrer">Cloud9 IDE</a> (c9) and so far it looks great, except a few minor things.</p>
  
  <p>I see from the docs that to start up a simple node.js http server, you have to pass in process.env.PORT in place of the regular port such as "8080".</p>
  
  <p>Node Hello World <a href="https://docs.c9.io/writing_nodejs_hello_world.html" rel="noreferrer">example</a>:</p>
  
  <pre><code> var http = require('http');
   http.createServer(function (req, res) {
       res.writeHead(200, {'Content-Type': 'text/plain'});
       res.end('Hello World\n');
   }).listen(process.env.PORT, process.env.IP);
  </code></pre>
  
  <p>What I want to know is, on c9, can you only start services on ports using javascript / node.js? Or do other languages work just as well, perhaps with some other method of passing the port? Specifically python + Twisted?</p>
  
  <p>I uploaded some twisted code that was working locally for me, but wouldn't work on c9 because it was trying to access local ports (which are already in use). Here is the error</p>
  
  <pre><code>twisted.internet.error.CannotListenError: Couldn't listen on any:8080: [Errno 98] Address already in use.
  </code></pre>
  
  <p>How would one make the following example work, if even possible, running on c9?</p>
  
  <p>Python+Twisted Hello World <a href="http://twistedmatrix.com/documents/current/web/howto/using-twistedweb.html" rel="noreferrer">example</a></p>
  
  <pre><code>from twisted.web import server, resource
  from twisted.internet import reactor
  
  class Simple(resource.Resource):
      isLeaf = True
      def render_GET(self, request):
          return "&lt;html&gt;Hello, world!&lt;/html&gt;"
  
  site = server.Site(Simple())
  reactor.listenTCP(8080, site)
  reactor.run()
  </code></pre>
  
  <p>Initial searches through the <a href="https://docs.c9.io/" rel="noreferrer">documentation</a> and github <a href="https://github.com/ajaxorg/cloud9/issues" rel="noreferrer">issues</a> did not turn much up. I'm hoping this is possible and I just missed the right parameter to pass.</p>
  
  <hr>
  
  <p>Edit: Updated output below</p>
  
  <p>Node Code</p>
  
  <pre><code>console.log(process.env.PORT)
  console.log(process.env.IP)
  </code></pre>
  
  <p>Terminal output</p>
  
  <pre><code>Running Node Process
  Tip: you can access long running processes, like a server, at 'http://private-cloud.mrchampe.c9.io'.
  Important: in your scripts, use 'process.env.PORT' as port and 'process.env.IP' as host.
  8080
  127.6.70.129
  </code></pre>
  
  <p>Python Code</p>
  
  <pre><code>import os
  
  print os.environ["PORT"]
  print os.environ["IP"]
  </code></pre>
  
  <p>Terminal output</p>
  
  <pre><code>Running Python Process
  8080
  127.6.70.129
  </code></pre>
  
  <p>Twisted code</p>
  
  <pre><code>import os
  import twisted
  
  from twisted.web import server, resource
  from twisted.internet import reactor
  
  class Simple(resource.Resource):
      isLeaf = True
      def render_GET(self, request):
          return "&lt;html&gt;Hello, world!&lt;/html&gt;"
  
  site = server.Site(Simple())
  
  reactor.listenTCP(int(os.environ["PORT"]), interface=os.environ["IP"])
  reactor.run()
  </code></pre>
  
  <p>Terminal Output</p>
  
  <pre><code>Running Python Process
  hello world
  Traceback (most recent call last):
    File "python/hello.py", line 17, in &lt;module&gt;
  
  reactor.listenTCP(int(os.environ["PORT"]), interface=os.environ["IP"])
  TypeError: listenTCP() takes at least 3 non-keyword arguments (2 given)
  </code></pre>
  
  <p>The <a href="http://twistedmatrix.com/documents/8.2.0/api/twisted.internet.interfaces.IReactorTCP.listenTCP.html" rel="noreferrer">listenTCP</a> TypeError is strange because 2 arguments works locally but not on Cloud9. I don't see why using these arguments does not work.</p>
  
  <p>I have the above code hosted on <a href="https://c9.io/mrchampe/python-twisted" rel="noreferrer">this</a> public Cloud9 project for anyone to take a look. Thanks!</p>