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

Client side 'close-connection' doesn't trigger on-close of server side #59

Open
nutora opened this issue Oct 20, 2021 · 2 comments
Open

Comments

@nutora
Copy link

nutora commented Oct 20, 2021

  • Server-side code
(ql:quickload '(:websocket-driver-server :clack))

(use-package :websocket-driver)

(defvar *echo-server*
  (lambda (env)
    (let ((ws (make-server env)))
      (on :message ws
          (lambda (message)
            (send ws message)))
      (on :close ws
          (lambda (&key code reason)
            (declare (ignore code reason)
                     (format t "...~a disconnected.~%" ws))))
      (lambda (responder)
        (declare (ignore responder))
        (start-connection ws)))))

;; Start Wookie server
(clack:clackup *echo-server* :port 5000)
  • Client-side

(defvar *client* (wsd:make-client "ws://localhost:5000/echo"))

(wsd:start-connection *client*)
(wsd:on :message *client*
        (lambda (message)
          (format t "~&Got: ~A~%" message)))
(wsd:send *client* "Hi")
(wsd:close-connection *client*) ;;this won't trigger sever-side's on :close

if connected the server with browser, when close the tab in browser or just close the browser, that call-back function will trigger, what have i missed in all of this ? please help, struggled in this for weeks

@anranyicheng
Copy link
Contributor

Hi, I find that :
(on :close ws
(lambda (&key code reason)
(declare (ignore code reason)
(format t "...a disconnected.%" ws))))
should be:
(on :close ws
(lambda (&key code reason)
(declare (ignore code reason))
(format t "...a disconnected.%" ws)))
You miss ")" in declcare context.
wish!

@anranyicheng
Copy link
Contributor

And, if you want to close server client connection, you should design traffic protocol, for example [https://github.com//issues/39]

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