Connected successful. But cannot receive any data.
xtang opened this issue · comments
Below is my test code:
(ns websocket-server.core
(:gen-class)
(:use [ring.adapter.jetty9])
(:import (org.eclipse.jetty.websocket.api Session)))
(defn dummy-app [req]
{:status 200})
(defn -main
"I don't do a whole lot ... yet."
[& args]
(run-jetty dummy-app {:port 50524
:join? false
:websockets {"/path" {:create-fn (fn [ring-request-map]
{:status 200})
:connect-fn (fn [ring-request-map ^Session ws-conn ring-session]
(prn "connect-fn"))
:text-fn (fn [ring-request-map ^Session ws-session ring-session message]
(prn "text-fn"))
:binary-fn (fn [ring-request-map ^Session ws-session ring-session payload offset len]
(prn "binary-fn"))
:close-fn (fn [ring-request-map ring-session statusCode reason]
(prn "close-fn"))
:error-fn (fn [ring-request-map ring-session e]
(prn "error-fn"))}}}))
Note: the version is 0.5.0
Please help:)
oh, sorry. The new websocket API is merged from a pull request. I will look into it.
Thanks:)
I cannot reproduce this error. Note that you need to connect to ws://localhost:50524/path/
. The trailing slash is required. Otherwise, Jetty will returns a 302 to redirect you to /path/
, however, most websocket clients could not deal with that redirect.
I have fixed some issues with 0.5.x and a new 0.5.2 is available from clojars.
I might change the websocket API in next release because the arguments of these functions are confusing.
@@!
Sorry, I forgot to commit the Fixed missing argument
...
It's wired that I connected to '/path/' successfully, but the server seems no response for ws.send('hello').
hmmm... the current API design for websocket handler is pretty bad.
I need some rework on proxy-ws-handler. In the original WebSocketAdaptor, we will call this.getRemote().sendString() to send something.
For a better API:
- all of these handler functions should be optional
- these functions do not have to accept a ring-session and ring-request-map
- we need to pass a websocket object to these functions so we can send message to clients
It won't be difficult. I will work on this tomorrow.
Currently, in order to echo message back to client, you will need to call
:text-fn (fn [_ session _ message]
(.. session (getRemote) (sendString message)))
Hi, Ning:
I will close this issue, because I found it's not related to the ring-jetty9-adapter, but the compatibility between jetty9 and jdk. I was using jdk1.7.0_05 which does not work with jetty9. After upgrading the jdk to 1.7.0_51, everything goes well.
Thanks for help!!
I just release 0.6.0 and cleaned up websocket APIs. I think it's far better than 0.5.x.
I didn't implement all functions provided by Jetty. If you find something missing or broken in the new API, feel free to submit an issue.