[Newbie] emrun small problem (port is already open)

23 views
Skip to first unread message

Flix

unread,
Jul 18, 2019, 8:48:23 AM7/18/19
to emscripten-discuss
Hi.
I'm starting to use emrun to run html files locally, because it seems that Firefox Quantum version 68 can't serve local files anymore (probably for some security reason).

Now I've made some naive scripts to run my main.html using emrun, but after some time I've discovered that it doesn't work anymore:
.../emsdk/upstream/emscripten/emrun.py", line 1641, in run
    httpd = HTTPWebServer((options.hostname, options.port), HTTPHandler)
  File "
/usr/lib/python2.7/SocketServer.py", line 417, in __init__
    self.server_bind()
  File "
/usr/lib/python2.7/BaseHTTPServer.py", line 108, in server_bind
    SocketServer.TCPServer.server_bind(self)
  File "
/usr/lib/python2.7/SocketServer.py", line 431, in server_bind
    self.socket.bind(self.server_address)
  File "
/usr/lib/python2.7/socket.py", line 228, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 98] Address already in use

After having read that by default the port used by emrun is 6931, I checked and discovered that the port is already open :
lsof -i :6931
COMMAND  PID USER   FD   TYPE DEVICE SIZE
/OFF NODE NAME
python  
3368 flix    3u  IPv4  59440      0t0  TCP localhost:6931 (LISTEN)

So, the naive question is: how can I close it to "reset" the emrun call?

Thank you in advance.

Flix

unread,
Jul 18, 2019, 9:01:44 AM7/18/19
to emscripten-discuss

Just found a possible (uncomfortable) solution:
> lsof -i :6931
COMMAND  PID USER   FD   TYPE DEVICE SIZE
/OFF NODE NAME
python  
3368 flix    3u  IPv4  59440      0t0  TCP localhost:6931 (LISTEN)
> kill 3368
> lsof -i :6931
[nothing more]
 
Is there better/automatic way of doing it?
 

Flix

unread,
Jul 18, 2019, 9:33:04 AM7/18/19
to emscripten-discuss
OK, I've made this script for Linux that seems to work (well, it still needs CTRL+C to close the terminal, but then the port is closed).

 Script "main.html.sh" in the same folder as main.html
#!/bin/bash
source
/.../emsdk/
path_to_my_emsdk_env.sh
# Check and close port if open
MYPID
=`lsof -i :6931 | sed -n '2p' | awk '{print $2}'`
if [ -n "${MYPID}" ]; then
   
#echo $MYPID
    kill $MYPID
fi
# Execute html
emrun
--kill_start --kill_exit main.html
# Check and close port if open
MYPID
=`lsof -i :6931 | sed -n '2p' | awk '{print $2}'`
if [ -n "${MYPID}" ]; then
   
#echo $MYPID
    kill $MYPID
fi


It's not perfect and there are better solutions for sure, but to me it's enough.

Hope it helps.

Reply all
Reply to author
Forward
0 new messages