Disconnect by client won't notify server
muyinliu opened this issue · comments
While client disconnecting, method hunchensocket:client-disconnected
is never call.
Hmmm, this is intriguing, can you provide more information about how you triggered this?
Environment:
OS: Mac OS X 10.10.4
Common Lisp: SBCL 1.2.11
hunchentoot-1.2.31
hunchensocket-20150302-git
;;;; hunchensocket-test.lisp
(ql:quickload 'hunchensocket)
(defpackage :hunchensocket-test
(:use :cl))
(in-package :hunchensocket-test)
(defclass client (hunchensocket:websocket-client)
((name :initarg :user-agent :initform (error "Name this client!") :accessor name)))
(defclass resource (hunchensocket:websocket-resource)
((name :initarg :name :initform (error "Name this resource!") :accessor name))
(:default-initargs :client-class 'client))
(defvar *resource-list* (list (make-instance 'resource :name "/resource")))
(defun find-resource (request)
(find (hunchentoot:script-name request) *resource-list* :test #'string= :key #'name))
(pushnew 'find-resource hunchensocket:*websocket-dispatch-table*)
(defun broadcast (resource message &rest args)
(loop for peer in (hunchensocket:clients resource)
do (hunchensocket:send-text-message peer (apply #'format nil message args))))
(defvar *resource* nil)
(defmethod hunchensocket:client-connected ((resource resource) client)
(setf *resource* resource)
(broadcast resource "~A has joined ~A" (name client) (name resource)))
(defmethod hunchensocket:client-disconnected ((resource resource) client)
(broadcast resource "~A has left ~A" (name client) (name resource)))
(defmethod hunchensocket:text-message-received ((resource resource) client message)
(format *terminal-io* "~A says ~A~%" (name client) message))
(defvar *server* (make-instance 'hunchensocket:websocket-acceptor :port 12345))
(hunchentoot:start *server*)
After running server on localhost, using WebSocket.org's Echo Test to connect to ws://localhost:12345/resource
, connect success, but press button Disconnect
on this page will NOT trigger client-disconnected
.
Note: CLWS successfully trigger client-disconnected
in the same situation.
It works for me under Windows and Allegro CL 9.0 64bit. I'll have a look at it when I get home. Unless you beat me to it :-)
Can you trace HUNCHENSOCKET::READ-HANDLE-LOOP and HUNCHENSOCKET::HANDLE-FRAME around the time you disconnect in the web client and paste the results here ?
Wait a second.
1: (HUNCHENSOCKET::HANDLE-FRAME
#<HUNCHENSOCKET-TEST::RESOURCE (1 connected clients of class CLIENT)>
#<HUNCHENSOCKET-TEST::CLIENT {100668E993}>
#<HUNCHENSOCKET::FRAME {100679D663}>)
1: HUNCHENSOCKET::HANDLE-FRAME returned :CLOSED
0: HUNCHENSOCKET::READ-HANDLE-LOOP returned NIL
Sorry, my fault... It did notify the server. This issue will be closed. Sorry again...