websocket传输对象
时间: 2023-09-22 08:11:29 浏览: 163
在WebSocket传输过程中,如果直接使用javax.websocket.Session.getBasicRemote().sendObject(map)方法传递对象,会出现以下错误:javax.websocket.EncodeException: No encoder specified for object of class [class org.********]。同样地,当在服务端使用WebSocket的sendObject方法直接向前端传递一个对象时,也会报错:javax.websocket.EncodeException: No encoder specified for object of class [这里是你sendObject里传的对象的全名]。
为了解决这个问题,我们可以使用jschan websocket传输。jschan是基于节点流的JavaScript端口,可以通过npm install jschan-ws --save命令进行安装,并创建一个新的websocket会话。URL的格式可以是"ws://localhost",也可以是一个对象。通过使用这种方式,我们可以顺利传输对象而不出现上述的编码错误。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [WebSocket(二):传递对象](https://blog.csdn.net/litterpp/article/details/77853383)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [【详细】WebSocket传递对象(sendObject方法)报错解决方案](https://blog.csdn.net/Useless_code/article/details/119384157)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [jschan-ws:jschan的WebSocket传输](https://download.csdn.net/download/weixin_42129300/18806792)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文