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

how to get a response like 'Clean: true, ..' after script executed #440

Open
standzhou2 opened this issue Apr 19, 2023 · 6 comments
Open

Comments

@standzhou2
Copy link

standzhou2 commented Apr 19, 2023

greeter.py

#!/usr/bin/env python
# encoding: utf-8
from sys import stdin, stdout

# For each line FOO received on STDIN, respond with "Hello FOO!".
while True:
  line = stdin.readline().strip()
  if line == 'bye':
     print('bye')
     stdout.flush()
     break
  print('Hello %s!' % line)
  stdout.flush() # Remember to flush

start command
./websocketd -port 8889 --loglevel debug --ssl --sslcert=cert/server.crt --sslkey=cert/server.key --dir=script --devconsole

in this case , browser side got a response like 'Clean: false..'
i want to get a response with 'Clean: true,.., what's wrong with my script above, help pls

image

@matvore
Copy link

matvore commented Apr 19, 2023 via email

@standzhou2
Copy link
Author

standzhou2 commented Apr 20, 2023

thank you so much
i just have a try, it seems not work.

image

image

@matvore
Copy link

matvore commented Apr 22, 2023

I looked a little more closely.

The gorilla/websocket library that websocketd uses allows sending a CloseMessage and other control messages, but websocketd doesn't expose an API to use that.

If you attempt to write 0xff, 0x00 or other control codes in the websocket script, websocketd ends up treating that as plain data, and wrapping that in a data packet when sending to the client. This includes the case of passing --binary to websocketd.

Maybe you can use some app-specific indicator, a normal data packet, for the server to communicate clean closure?

@ctn-malone
Copy link

If you're under linux, you can try to use https://github.com/ctn-malone/websocketd-controller which can be used as a wrapper around your script and will forward stdout, stderr & exit event (which contain the exit code of the wrapped script)

@asergeyev
Copy link
Collaborator

What is difference that clean:true would make?

@ctn-malone
Copy link

ctn-malone commented Jun 27, 2023

It’s just an easy way to get json events everytime something is outputted to stdout, stderr or if the program exits. I like the standard way of communicating it provides but I might be a bit biased 😅

Edit: on second thought, I probably misread @asergeyev question (I thought you asked what benefit would be provided by the wrapper)

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

4 participants