Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server, opened() is called each time a message is send #162

Closed
heppg opened this issue Apr 6, 2015 · 7 comments
Closed

server, opened() is called each time a message is send #162

heppg opened this issue Apr 6, 2015 · 7 comments

Comments

@heppg
Copy link

heppg commented Apr 6, 2015

Using websocket with cherrypy.
Whenever I pass a message from client to server, the server's opened-method is called.
I assume that this method should be called only once per successful connection.

@Lawouach
Copy link
Owner

Lawouach commented Apr 6, 2015

Indeed, it should only becalled once when the connection was created. That is weird. Which versions of CP/ws4py are you running?

@heppg
Copy link
Author

heppg commented Apr 6, 2015

CherryPy==3.6.0
ws4py==0.3.4

The purpose of the code is: for a school class. I maintain a client for scratch, which allows for hardware access on raspberry pi. This code has an embedded web server to display current configuration and some events.

The code is derived from the Echo-Sample. But I use the RoutesDispatcher.
Some fragments attached: setup of cherrypy, the handler, fragment of the WebSocket implementation.
The client (firefox, javascript) reports connection open only once.

[code]WebSocketPlugin(cherrypy.engine).subscribe()
cherrypy.tools.websocket = WebSocketTool()

animationHandler = AnimationHandler()

dispatcher.connect(name='adapterAnimation' , route='/ws' , controller=animationHandler , action='ws')
conf['/ws'] = {
'tools.websocket.on': True,
'tools.websocket.handler_cls': AdapterAnimationWebSocket
}
[/code]

[code]
class AnimationHandler(object):
def ws(self):
# you can access the class instance through
handler = cherrypy.request.ws_handler
[/code]

[code]
class AdapterAnimationWebSocket(WebSocket):
def init(self, sock, protocols=None, extensions=None, environ=None, heartbeat_freq=None):
WebSocket.init(self, sock, protocols, extensions, environ, heartbeat_freq)
print ("init")
self.state = 0

def opened(self):
    if ( self.state == 1):
        print ("AdapterAnimationWebSocket.opened (multiple)")
    if ( self.state == 0):
        self.state = 1
        print ("AdapterAnimationWebSocket.opened")

[/code]

@Lawouach
Copy link
Owner

Lawouach commented Apr 6, 2015

I've never tried ws4py with the RoutesDispatcher so I'm wondering if there isn't some sort of corner case with that dispatcher.

How many times do you the log from the ws4py manager:

Managing websocket ...

?

@heppg
Copy link
Author

heppg commented Apr 6, 2015

ws4py - 243 - INFO - Managing websocket [Local => 127.0.0.1:8080 |
Remote => 127.0.0.1:58236]
is logged only once, although "AdapterAnimationWebSocket.opened
(multiple)" is reported multiple times.

When terminating connection (by closing client web page), I get
2015-04-06 22:28:31,108 - ws4py - 360 - DEBUG - Closing message received
(1001) ''
2015-04-06 22:28:31,108 - ws4py - 317 - INFO - Terminating websocket
[Local => 127.0.0.1:8080 | Remote => 127.0.0.1:58236]

Looks strange.
A threading problem ? The system is using multiple threads, and calling
the send function is from various threads (not decoupled by queues so far).

On 06.04.2015 19:23, Sylvain Hellegouarch wrote:

I've never tried ws4py with the RoutesDispatcher so I'm wondering if
there isn't some sort of corner case with that dispatcher.

How many times do you the log from the ws4py manager:

Managing websocket ...

?


Reply to this email directly or view it on GitHub
#162 (comment).

@Lawouach
Copy link
Owner

Lawouach commented Apr 7, 2015

I must say I'm a bit puzzled honestly. I can't figure out where the opened() method could be called elsewhere. So, it could be a thread issue but I fail to identify it :(

@heppg
Copy link
Author

heppg commented Apr 7, 2015

Found the problem in my code (better: in front of my computer).
Websocket code is working fine.

Thank you for your support !

On 07.04.2015 13:18, Sylvain Hellegouarch wrote:

I must say I'm a bit puzzled honestly. I can't figure out where the
opened() method could be called elsewhere. So, it could be a thread
issue but I fail to identify it :(


Reply to this email directly or view it on GitHub
#162 (comment).

@Lawouach
Copy link
Owner

Lawouach commented Apr 7, 2015

Well... that's a relief. Enjoy! :D

@Lawouach Lawouach closed this as completed Apr 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants