0
我在Netty框架上開發新功能。Netty:基於URI的Websocket網絡
我寫了一些使用它的聊天模塊。
這是我簡單的聊天服務器項目片段ChannelInitializer
。
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new HttpServerCodec())
.addLast(new HttpObjectAggregator(65536))
.addLast(new LoggingHandler(LogLevel.INFO))
.addLast(new WebSocketServerProtocolHandler("/chat"))
.addLast(new WsUserAcceptHandler())
...
這很簡單。每個處理程序檢查來自/chat
的消息,並決定是否處理。
但現在,我想給每個處理程序提供唯一的URI。 你能給我一些提示嗎?
你是什麼意思「給每個處理程序唯一的URI」? – Jire
呃...對不起英語不好。 例如,當我要求'/ chat/join/1'時,'WsUserAcceptHandler'處理這個請求,'/ chat/message/1'然後'WsMessagingHandler'處理這個。但爲什麼我想知道這一點,'新的WebSocketServerProtocolHandler(「/聊天」)'指定一些URI,我認爲這意味着只有升級到某些URI的websocket連接。 –