Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Websocket Clojure:如何验证web套接字用户?_Websocket_Clojure_Http Kit - Fatal编程技术网

Websocket Clojure:如何验证web套接字用户?

Websocket Clojure:如何验证web套接字用户?,websocket,clojure,http-kit,Websocket,Clojure,Http Kit,我一直在关注,后来在试图找到一种将WS通道映射到后端用户的惯用方法时遇到了困难 我尝试使用Java反射检查org.httpkit.server.AsyncChannel对象,并获得以下属性: | :name | :return-type | :declaring-class | :parameter-type

我一直在关注,后来在试图找到一种将WS通道映射到后端用户的惯用方法时遇到了困难

我尝试使用Java反射检查org.httpkit.server.AsyncChannel对象,并获得以下属性:

|                           :name |         :return-type |                :declaring-class |                                               :parameter-types |      :exception-types |              :flags |
|---------------------------------+----------------------+---------------------------------+----------------------------------------------------------------+-----------------------+---------------------|
|                       chunkSize |  java.nio.ByteBuffer | org.httpkit.server.AsyncChannel |                                                          [int] |                    [] | #{:private :static} |
|                      firstWrite |                 void | org.httpkit.server.AsyncChannel |                                     [java.lang.Object boolean] | [java.io.IOException] |         #{:private} |
|                        isClosed |              boolean | org.httpkit.server.AsyncChannel |                                                             [] |                    [] |          #{:public} |
|                     isWebSocket |              boolean | org.httpkit.server.AsyncChannel |                                                             [] |                    [] |          #{:public} |
|                 messageReceived |                 void | org.httpkit.server.AsyncChannel |                                             [java.lang.Object] |                    [] |          #{:public} |
|                         onClose |                 void | org.httpkit.server.AsyncChannel |                                                          [int] |                    [] |          #{:public} |
| org.httpkit.server.AsyncChannel |                      | org.httpkit.server.AsyncChannel | [java.nio.channels.SelectionKey org.httpkit.server.HttpServer] |                    [] |          #{:public} |
|                    pingReceived |                 void | org.httpkit.server.AsyncChannel |                                                       [byte<>] |                    [] |          #{:public} |
|                        readable | clojure.lang.Keyword | org.httpkit.server.AsyncChannel |                                                          [int] |                    [] | #{:private :static} |
|                           reset |                 void | org.httpkit.server.AsyncChannel |                               [org.httpkit.server.HttpRequest] |                    [] |          #{:public} |
|                            send |              boolean | org.httpkit.server.AsyncChannel |                                     [java.lang.Object boolean] | [java.io.IOException] |          #{:public} |
|                   sendHandshake |                 void | org.httpkit.server.AsyncChannel |                                                [java.util.Map] |                    [] |          #{:public} |
|                     serverClose |              boolean | org.httpkit.server.AsyncChannel |                                                          [int] |                    [] |          #{:public} |
|                 setCloseHandler |                 void | org.httpkit.server.AsyncChannel |                                             [clojure.lang.IFn] |                    [] |          #{:public} |
|                  setPingHandler |                 void | org.httpkit.server.AsyncChannel |                                             [clojure.lang.IFn] |                    [] |          #{:public} |
|               setReceiveHandler |                 void | org.httpkit.server.AsyncChannel |                                             [clojure.lang.IFn] |                    [] |          #{:public} |
|                        toString |     java.lang.String | org.httpkit.server.AsyncChannel |                                                             [] |                    [] |          #{:public} |
|                      writeChunk |                 void | org.httpkit.server.AsyncChannel |                                     [java.lang.Object boolean] | [java.io.IOException] |         #{:private} |
nil
我唯一能想到的是:

1) 保持
连接按原样运行:

(defonce channels (atom #{}))

(defn connect! [channel]
  (log/info "channel open" channel)
  (swap! channels conj channel))
2) 更新WebSocket客户端,在建立WS连接后立即将JWT或环形会话id作为第一条消息发送,WS连接允许将该(已建立的)通道映射到可以识别用户的标识符(JWT或环形会话id)

这有意义吗?或者这是一个严重的反模式和WS-RFCs冲突?对不起,我以前没有在这么低的级别上使用WebSocket

(defonce channels (atom #{}))

(defn connect! [channel]
  (log/info "channel open" channel)
  (swap! channels conj channel))