<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Launching a httpdserver]]></title><description><![CDATA[<p dir="auto">I'm using a browser inside RF for testing fonts inside the app without any need to launch another program. So far the idea is working very well. But for some reason I need to launch a http server inside the RF which seems to be impossible. Running a simple http server outside RF is very simple. I just need to run this in shell:</p>
<pre><code class="language-console">&gt; cd cwd
&gt; python -m SimpleHTTPServer 8080
</code></pre>
<p dir="auto">I've realized that every python command should be terminated in the Robofont and if the command is still running the app halts and launching the <code>HTTPServer</code> makes the app hang. If it was possible to run the server on another thread it would be great too but when the server is launched on another thread with the following method the server terminates after the interpreter reaches the last line.</p>
<pre><code class="language-python">import threading
import SimpleHTTPServer
import SocketServer

class RunHttpdServer():

    '''
    Runs a httpd server on another thread so you can
    do other things while the server is running.
    '''

    def __init__(self):
        self.Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
        self.port = 8000
        self.address = ''
        while True:
            try:
                self.httpd = SocketServer.TCPServer(('', self.port), self.Handler)
                self.address = 'http://localhost:%s/' % self.port
                print 'Serving on address:\n%s' % self.address
                self.thread = threading.Thread(target=self.httpd.serve_forever)
                self.thread.daemon = True
                self.thread.start()
            except SocketServer.socket.error as exc:
                if exc.args[0] != 48:
                    raise
                print 'Port', self.port, 'already in use'
                self.port += 1
            else:
                break

    def stop(self):
        self.httpd.shutdown()
        print 'Server terminated on the address:\n%s' % self.address

r = RunHttpdServer()
</code></pre>
<p dir="auto">I can use the <code>time.sleep(10)</code> to make the server alive but it will also make the app hang. Do you think is there anyway to launch the server within RF and making it run forever (or a limited time) without making the RF hang? For example like launching another process in the background.</p>
<p dir="auto">Thanks in advance</p>
]]></description><link>https://forum.robofont.com/topic/411/launching-a-httpdserver</link><generator>RSS for Node</generator><lastBuildDate>Sat, 15 Aug 2026 04:54:34 GMT</lastBuildDate><atom:link href="https://forum.robofont.com/topic/411.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 15 Nov 2016 01:43:01 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Launching a httpdserver on Wed, 03 Jan 2018 18:56:54 GMT]]></title><description><![CDATA[<p dir="auto">I'm using a browser inside RF for testing fonts inside the app without any need to launch another program. So far the idea is working very well. But for some reason I need to launch a http server inside the RF which seems to be impossible. Running a simple http server outside RF is very simple. I just need to run this in shell:</p>
<pre><code class="language-console">&gt; cd cwd
&gt; python -m SimpleHTTPServer 8080
</code></pre>
<p dir="auto">I've realized that every python command should be terminated in the Robofont and if the command is still running the app halts and launching the <code>HTTPServer</code> makes the app hang. If it was possible to run the server on another thread it would be great too but when the server is launched on another thread with the following method the server terminates after the interpreter reaches the last line.</p>
<pre><code class="language-python">import threading
import SimpleHTTPServer
import SocketServer

class RunHttpdServer():

    '''
    Runs a httpd server on another thread so you can
    do other things while the server is running.
    '''

    def __init__(self):
        self.Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
        self.port = 8000
        self.address = ''
        while True:
            try:
                self.httpd = SocketServer.TCPServer(('', self.port), self.Handler)
                self.address = 'http://localhost:%s/' % self.port
                print 'Serving on address:\n%s' % self.address
                self.thread = threading.Thread(target=self.httpd.serve_forever)
                self.thread.daemon = True
                self.thread.start()
            except SocketServer.socket.error as exc:
                if exc.args[0] != 48:
                    raise
                print 'Port', self.port, 'already in use'
                self.port += 1
            else:
                break

    def stop(self):
        self.httpd.shutdown()
        print 'Server terminated on the address:\n%s' % self.address

r = RunHttpdServer()
</code></pre>
<p dir="auto">I can use the <code>time.sleep(10)</code> to make the server alive but it will also make the app hang. Do you think is there anyway to launch the server within RF and making it run forever (or a limited time) without making the RF hang? For example like launching another process in the background.</p>
<p dir="auto">Thanks in advance</p>
]]></description><link>https://forum.robofont.com/post/410</link><guid isPermaLink="true">https://forum.robofont.com/post/410</guid><dc:creator><![CDATA[bahman]]></dc:creator><pubDate>Wed, 03 Jan 2018 18:56:54 GMT</pubDate></item><item><title><![CDATA[Reply to Launching a httpdserver on Wed, 03 Jan 2018 19:42:58 GMT]]></title><description><![CDATA[<p dir="auto">As far as I understand this example, this will run forever until a traceback is raised.</p>
<p dir="auto">This seems to work fine with an <code>htmlView</code> inside RoboFont.</p>
<p dir="auto">Good luck</p>
]]></description><link>https://forum.robofont.com/post/1438</link><guid isPermaLink="true">https://forum.robofont.com/post/1438</guid><dc:creator><![CDATA[frederik]]></dc:creator><pubDate>Wed, 03 Jan 2018 19:42:58 GMT</pubDate></item></channel></rss>