4

I'm trying to get the websockify 0.6.0 running on windows but without any luck,

I have tried python websockify.py 1501 10.0.0.141:1501 but its not good, getting errors , like that:

Traceback (most recent call last): File "websockify.py", line 1, in <module> run NameError: name 'run' is not defined

I also tried Compiling Websockify as Windows Executable , but this also didn't work I use the following command run.exe 1501 10.0.0.141:1501 and it looks promising at the beginning, outputting the following to the console:

WARNING: no 'resource' module, daemonizing is disabled WebSocket server settings: - Listen on :1501 - Flash security policy server - No SSL/TLS support (no cert file) - proxying from :1501 to 10.0.0.141:1501

but then after trying to connect using the following from the browser ws://localhost:1501

**it outputs the following error

Traceback (most recent call last): File "run", line 5, in <module> File "websockify\websocketproxy.pyc", line 419, in websockify_init File "websockify\websocket.pyc", line 1018, in start_server UnboundLocalError: local variable 'exc' referenced before assignment


Any idea on how to use the websockify on windows / or how to use the compiled websockify as windows executable ?

Daniel
  • 36,833
  • 10
  • 119
  • 200

2 Answers2

1

The easiest way to get websockify working on Windows is to use the Node.js version of websockify (in the other/js directory). It works perfectly out of the box, with no shenanigans required.

CpnCrunch
  • 4,831
  • 1
  • 33
  • 31
0

To address this, use the modified following commands for your example source, start from the beginning of each step and see if it helps:

  • Firstly, install Portable Python 2.7
  • You then need to modify the setup.py (It looks like this is why you are getting your first error, as you may not have defined run):
from setuptools import setup, find_packages
# add (line 2):
import py2exe

setup(name=name,
# add (line 10):
console=['run'],
  • Ensure the above has executed correctly by inspecting setup.py and ensure it includes run.

    • In your local code, import the resources module to allow you to monitor, measure and control system resources utilized by your program
import resource
  • Inspect your local variable exc and ensure you have assigned a value to it before calling it (I'm guessing you may have attributed a system variable to it, but python was unable to do so as you did not have resources imported, and as such it was not assigned). If you like, put up an example of your code in the comment to this response and I'll take a closer look at this part.

  • Back to your source guide, navigate to the websockify folder in command prompt, then execute the following to compile websockify:

[Your path to Portable Python install]\App\python.exe setup.py py2exe --includes numpy
  • You will now see in the websockify directory a new dir 'dist' which contains the compiled exe. An example provided is:
run.exe 5901 localhost:5900

There is also a guide here to run websockify as a Windows Service if this suits (again mentioned in your source).

----Further edit for more detail----

Open up the two files that seem to be giving you issues (websockify\websocketproxy.pyc and websockify\websocket.pyc and ensure that any reference to a variable called "exc" is referenced after it has been assigned a value (small chance of an issue if you have not yet modified these files.

I believe that your code is relying upon making and monitoring changes to the system resources (such as ports etc) and you are not allowing your code to have these permissions, so it needs the resources module. If you are calling run.exe from a program (what I called your local code) then you need to import resources at the top. If you are just straight up calling the run.exe program from a command line, then try making this new program and see if this helps. If not, send me the contents of your websockify folder and run.exe and I will take a look

# Program Name: goAndRun.py

# Code:

import sys, string, os, arcgisscripting, resource
os.chdir( 'C:\\[Path_to_the_dir_containing_run.exe]' )
os.system( '"C:\\[Path_to_the_dir_containing_run.exe]\run.exe, 5901 localhost:5900"' )

And then use the command:

python goAndRun.py

Not being in your environment, I cannot tell if this will execute exactly as I have written it. The last line may also be:

os.system( '"C:\\[Path_to_the_dir_containing_run.exe]\run.exe"', '5901 localhost:5900' )
KyleM
  • 508
  • 2
  • 4
  • 11
  • 1
    Thanks for the answer, but 99% of your answer is a copy paste the content of the link I have posted and already tried successfully (at least the build but and generating executable...) the only added value you mentioned is the 'import resource' , where should I insert that line and how can it help me? – Daniel Sep 20 '14 at 19:08
  • @Daniel, as stated in my response, I simply took the code from your source and modified it with a couple of lines and extra notes. This response will hopefully not only help you, but also help others who search this issue. I have written there to put it in your local code, import statements go at the top of a python code (underneath a shebang line if you have one, e.g. #!/usr/bin/python then import resource on the next line) I have also now put bold around the lines that are important to you in addition to what was written in the source. – KyleM Sep 21 '14 at 21:49
  • @Daniel I am sorry that you feel this was only 1% added value, however hopefully this is the 1% you need to get it working. – KyleM Sep 21 '14 at 21:54
  • I already stated that I have tried the tutorial in the "Compiling Websockify as Windows Executable" link (that link from which you did the copy paste, I already followed that steps and modified my setup.py but after doing so I got the errors I posted in my question, You said "In your local code, import the resources" what local code are you referring to? all I got is that websockify folder and the setup.py, don't get me wrong, I do appreciate the attempt, but all your answer is is taken from a link that I posted in my question and stated that tried without luck. – Daniel Sep 22 '14 at 17:41
  • @Daniel, let's move away from the copy paste, the reason I have done this is to clearly and unambiguously show you the points at which to make changes, rather than state "After step 3, do this..." I have updated my answer to give a more detailed explanation at the bottom. – KyleM Sep 22 '14 at 22:00