【问题标题】:Autobahn Exception WebSockets protocol violation高速公路异常 WebSockets 协议违规
【发布时间】:2026-02-16 02:05:01
【问题描述】:

在我的 android 应用程序中,我想使用高速公路库来使用 websockets。

我认为服务器正在使用 Draft-17。 谁能告诉我,如何设置客户端以使用此协议?

我有这个代码:

      mConnection.connect(url,new String[] {"protocolname?"}, new WebSocketHandler() {

         //some functions
      },options);

问候

更新 在我的服务器上,我使用 8.1 版的 Jetty。

更新 LogCat 的输出是:

01-15 22:54:53.481: D/de.tavendo.autobahn.WebSocketReader(32452): created
01-15 22:54:53.491: D/de.tavendo.autobahn.WebSocketConnection(32452): WS reader created     and started
01-15 22:54:53.491: D/de.tavendo.autobahn.WebSocketReader(32452): running
01-15 22:54:53.491: D/de.tavendo.autobahn.WebSocketWriter(32452): created
01-15 22:54:53.491: D/de.tavendo.autobahn.WebSocketConnection(32452): WS writer created and started
01-15 22:54:53.551: D/de.tavendo.autobahn.WebSocketConnection(32452): opening handshake received
01-15 22:54:53.551: D/Websocket(32452): Status: Connected to ws://192.168.178.30:8080
01-15 22:54:53.551: D/de.tavendo.autobahn.WebSocketReader(32452): run() : WebSocketException (de.tavendo.autobahn.WebSocketException: RSV != 0 and no extension negotiated)
01-15 22:54:53.551: D/de.tavendo.autobahn.WebSocketReader(32452): ended
01-15 22:54:53.551: D/de.tavendo.autobahn.WebSocketConnection(32452): fail connection [code = 4, reason = WebSockets protocol violation
01-15 22:54:53.551: D/de.tavendo.autobahn.WebSocketReader(32452): quit
01-15 22:54:53.551: D/de.tavendo.autobahn.WebSocketWriter(32452): ended
01-15 22:54:53.551: D/Websocket(32452): Connection lost.
01-15 22:54:53.551: D/de.tavendo.autobahn.WebSocketConnection(32452): worker threads stopped

【问题讨论】:

    标签: android websocket jetty autobahn


    【解决方案1】:

    你是指 WebSocket 协议版本还是 WebSocket 子协议?

    关于前者:AutobahnAndroid 实现了 RFC6455(最后一个也是最终的 WebSocket 协议版本)。没有办法降级到旧版本,但基本上,从 Hybi-10+ 到 RFC6455 没有重大变化。

    关于后者:在打开 WebSocket 连接时指定 WebSocket 子协议,如this

    【讨论】:

    • 是的,WebSocket 协议。感谢您提供此信息。你知道如何将 Jetty 8.1 设置为 RFC6455 标准吗?
    • 不,抱歉。但可能你不需要做任何特别的事情。 WebSocket 协议版本在两个对等实现之间的初始 WebSocket 打开握手期间宣布和协商。
    • 好的,我的问题是我的 android 客户端在连接后断开连接。异常调用:`D/de.tavendo.autobahn.WebSocketConnection(6471):连接失败 [代码 = 4,原因 = WebSockets 协议违规'
    • 尝试启用调试输出,以便查看实际违规:github.com/tavendo/AutobahnAndroid/blob/master/Autobahn/src/de/…
    • 我有。我将输出发布到主要问题