fukamachi / websocket-driver

WebSocket server/client implementation for Common Lisp
BSD 2-Clause "Simplified" License
103 stars 27 forks source link

Trouble with echo #16

Closed pebblexe closed 7 years ago

pebblexe commented 7 years ago

With the following code:

(defvar *client* (wsd:make-client "ws://echo.websocket.org"))

(wsd:start-connection *client*)
(wsd:on :message *client*
        (lambda (message)
          (format t "~&Got: ~A~%" message)))
(wsd:send *client* "Hi")

Produces the following output:

; SLIME 2016-04-19
CL-USER> (ql:quickload 'wstest)
To load "wstest":
  Load 1 ASDF system:
    wstest
; Loading "wstest"
.....................
(WSTEST)
Got: Hi
CL-USER> (ql:quickload 'wstest)
To load "wstest":
  Load 1 ASDF system:
    wstest
; Loading "wstest"

(WSTEST)
CL-USER> (ql:quickload 'wstest)
To load "wstest":
  Load 1 ASDF system:
    wstest
; Loading "wstest"

(WSTEST)
CL-USER> 

So why does it only get a 'Hi' the first time? It seems like the repeated requests are not being sent/received properly.

pebblexe commented 7 years ago

Also it seems that sometimes I am getting multiple responses, but they are duplicates.


(defvar *client* (wsd:make-client "ws://echo.websocket.org"))

(wsd:start-connection *client*)
(wsd:on :message *client*
        (lambda (message)
          (format t "~&Got: ~A~%" message)))

;; (format t "sent!")
;; (wsd:send *client* "Hi")

(defun send ()
  (wsd:send *client* "Hi 1"))

And this is the response I am getting:

(wstest:send)
NIL
Got: Hi 1
Got: Hi 1
Got: Hi 1
Got: Hi 1
Got: Hi 1
Got: Hi 1
Got: Hi 1
Got: Hi 1

when I am only running the sending code once. Is that a bug? Why is it buffering?

Sorry for the odd question, I am new to common lisp.

pebblexe commented 7 years ago

Also it seems like it isn't responding with the actual output sometimes; it's just displaying a copy of the sent message as a response when tested against a non-echo server.

knobo commented 7 years ago

I don't have this problem. Have you upgraded your quicklisp?

pebblexe commented 7 years ago

I'm using the master branch of this and clack in my local-projects repository.

fukamachi commented 7 years ago

This is because of the way to invoke the file. Quicklisp won't load files again if those are already loaded and never changed since they were loaded. Try with REPL, it evaluates every time as you like. 2017年2月28日(火) 22:44 pebblexe notifications@github.com:

I'm using the master branch of this and clack in my local-projects repository.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/fukamachi/websocket-driver/issues/16#issuecomment-283042407, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFhymQUOhzlh3AbfynxZTX99RJe2XZcks5rhCTPgaJpZM4MNT1w .

pebblexe commented 7 years ago

Ah that's it! That explains why it only runs sometimes. Thank you fukamachi!

But what about the second issue with the 'buffered' echoes? I don't seem to be able to interact normally with a websocket server, as https://github.com/jnordberg/wscat has shown I am not getting the proper responses returned.

pebblexe commented 7 years ago

And now I'm receiving nothing when sending to ws://echo.websocket.org:

CL-USER> (ql:quickload 'wstest)
To load "wstest":
  Load 1 ASDF system:
    wstest
; Loading "wstest"

(WSTEST)
CL-USER> (wstest:send)
NIL
CL-USER> (wstest:send)
NIL
CL-USER> (wstest:send)
NIL
CL-USER> (wstest:send)
NIL
CL-USER> 
pebblexe commented 7 years ago

And now it's working after I restarted emacs!

(WSTEST)
CL-USER> (wstest:send)
NIL
Got: Hi 1
CL-USER> (wstest:send)
NIL
Got: Hi 1
CL-USER> 
pebblexe commented 7 years ago

Okay, now I get it. For some reason when I start up and client is bound to ws://echo.websocket.org it works and echoes. But when I restart the code and aim it at another websocket server it remains stuck to the original one (the echo server) despite reloading (ql:quickload 'wstest).

Why does ql:quickload not rebind the client defvar properly?

pebblexe commented 7 years ago

I think this whole thing is me being an idiot; this is a wonderful library.