Comments (8)
Hi.
I've tested exactly the code you provided and it worked without problems on my machine.
Have you tested to connect to the server with another client to see if the problem is really caused by ActionCableZwei?
Best
from python-actioncable-zwei.
Hi Tobias, thanks again. Connecting works with websocket-client and the code below. Meaning, the server shows it received a connect attempt. I'm stumped. It's the same URL. And I've allowed all remote origins in my rails server.
Debug Output when I connect using example code (I added one to the runforever area)
python3 ./my_actioncable.py
04/03/2017 09:53:14 PM my_actioncable INFO: Started
04/03/2017 09:53:14 PM monitor DEBUG: ACTIONCABLE MONITOR : Started.
04/03/2017 09:53:14 PM connection DEBUG: ACTIONCABLE CONNECTION : RUN FOREVER...
04/03/2017 09:53:14 PM connection DEBUG: ACTIONCABLE CONNECTION : Connect...
$ (end)
Here is the example code from websocket-client
import websocket
import thread
import time
import json
def on_message(ws, message):
print(message)
def on_error(ws, error):
print(error)
def on_close(ws):
print("### closed ###")
def on_open(ws):
msg = {'identifier': 'status_channel', 'command': 'message','message': 'FROM PYTHON'}
def run(*args):
for i in range(3):
time.sleep(1)
ws.send("{\"command\":\"subscribe\",\"identifier\":{\"channel\":\"MeshRelayChannel\"}}")
time.sleep(1)
ws.close()
print("thread terminating...")
thread.start_new_thread(run, ())
if __name__ == "__main__":
websocket.enableTrace(True)
ws = websocket.WebSocketApp("ws://localhost:3000/cable/",
on_message = on_message,
on_error = on_error,
on_close = on_close)
ws.on_open = on_open
ws.run_forever()
from python-actioncable-zwei.
Update: It works if I change line 54 of connection.py to call ws.run_forever() , instead of the internal function you have defined (_run_forever)
The thread isn't executing the ws
instance, so nothing gets kicked off. But I'm not sure why this works for you and not me?
self.ws_thread = threading.Thread(name="APIConnectionThread_{}".format(uuid.uuid1()), target=self.ws.run_forever())
from python-actioncable-zwei.
You actually call the run_forever
method in your code. So the websocket connection will now block your main thread. You have to pass the reference to the new thread, so without parentheses.
BTW The private method I use as thread loop does actually also nothing other than calling the run_forever
method of the ws
. See here.
Are you trying to call this program directly from the command line like in the example above?
from python-actioncable-zwei.
I see that now, your private method does end up calling the run_forever
method of the ws
. And yes, it does block the main thread (undesired!) but my server does receive responses.
Yes, I am trying to call this program directly. I am copying and pasting your code directly into a file, and then running 'python3 my_actioncable.py' Should I be running it differently, and I'm not understanding how to use this example?
I am running: python 3.6.1, macOS 10.12.3
from python-actioncable-zwei.
Then add this code at the end of your file:
while True:
pass
The connection thread is actually a daemonic thread so it's going to be killed if the main thread finishes. If you call an infinite loop in the main thread this will actually never stop and your connection should be established.
from python-actioncable-zwei.
Ahh, I see, that makes total sense. Threading 101. Thanks so much for putting with a newbie python guy. I really appreciate that you wrote this.
from python-actioncable-zwei.
Your welcome :) Have fun!
Best
from python-actioncable-zwei.
Related Issues (8)
- ModuleNotFoundError in examples HOT 1
- Outdated README/version number HOT 1
- Callback reference missing in Subscription example HOT 1
- Channels stuck in a 'pending' state HOT 2
- Unable to send cookie using ActionCableZwei HOT 6
- Cant suscribe to Channels, get stuck in 'pending' state
- Can't seem to work because of error on callbacks HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-actioncable-zwei.