How to use websockify with python on Windows or compile websockify as executables (for more multiple client connection at a time)

I am trying to run websockify 0.6.0 on windows but with no luck,

I tried python websockify.py 1501 10.0.0.141:1501

but it is not good, getting errors like:

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 a Windows executable , but that 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 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 browser ws://localhost:1501

** it throws 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 how to use websockify on Windows / or how to use the compiled websockify as a Windows executable?

+4


source to share


2 answers


To fix this issue, use the following modified commands for the sample source , start at the beginning of each step, and see if that helps:

  • First, install Portable Python 2.7
  • Then you need to change setup.py ( Sounds like this is why you get the first error, as you may not have defined a run ):
from setuptools import setup, find_packages
# add (line 2):
import py2exe

setup(name=name,
# add (line 10):
console=['run'],

      

  • Make sure the above is correct by checking setup.py and make sure it includes startup.

    • In your local code, import the resources module so you can monitor, measure and monitor the system resources used by your program
import resource

      

 
  • Inspect your local exc variable and make sure you assign a value to it before calling it (I assume you could assign a system variable to it, but python couldn't do that since you didn't import any resources and so it wasn't assigned). If you like, please provide an example of your code in the comment to this answer and I'll go over that part in more detail.

  • Go back to the original guide, navigate to the websockify folder on the command line, and then run the following command to compile websockify:

[Your path to Portable Python install]\App\python.exe setup.py py2exe --includes numpy

      

 
  • Now you will see a new dir 'dist' in your websockify directory that contains the compiled exe. The example given:
run.exe 5901 localhost:5900

      



 

There is also a guide here to run websockify as a Windows service, if appropriate (mentioned again in your source).

---- Further edits for more details ----

Open the two files that seem to be giving you problems (websockify \ websocketproxy.pyc and websockify \ websocket.pyc) and make sure the variable named "exc" is referenced after . a value has been assigned (unlikely to cause a problem if you haven't changed these files yet.

I believe your code relies on creating and monitoring changes to system resources (such as ports, etc.), and you are not allowing your code to have these permissions, so it needs a resource module. If you call run.exe from a program (what I called your local code) you need to import the resources at the top. If you are just calling the run.exe program directly from the command line, try making this new program and see if that helps. If not, send me the contents of your websockify and run.exe folder and I'll 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

      

Without being in your environment, I cannot tell if this will execute exactly as I wrote it. The last line could also be:

os.system( '"C:\\[Path_to_the_dir_containing_run.exe]\run.exe"', '5901 localhost:5900' )

      

0


source


The easiest way to get websockify to work on Windows is to use the Node.js version of websockify (in a different / js directory). It works great out of the box, without the need for shenanigans.



0


source







All Articles