【问题标题】:Send query parametres with connection apache paho websocket client使用连接 apache paho websocket 客户端发送查询参数
【发布时间】:2017-11-01 10:33:32
【问题描述】:

我有一个连接到代理的 mqtt 客户端。 我的经纪人拦截连接以从中获取令牌并做一些工作。 我想在连接时发送一个令牌作为查询参数。

我的客户端是这样连接的:

        MqttAsyncClient sampleClient = new MqttAsyncClient(broker, clientId, persistence);
        MqttConnectOptions connOpts = new MqttConnectOptions();

        connOpts.setCleanSession(false);

        connOpts.setAutomaticReconnect(true);
        connOpts.setKeepAliveInterval(MqttConnectOptions.KEEP_ALIVE_INTERVAL_DEFAULT);

        connOpts.setConnectionTimeout(MqttConnectOptions.CONNECTION_TIMEOUT_DEFAULT); 
        IMqttToken token = sampleClient.connect(connOpts);

我该怎么做?有人可以帮我吗?

【问题讨论】:

    标签: java websocket activemq paho broker


    【解决方案1】:

    如果您修改类WebSocketHandshake 中的方法sendHandshakeRequest,这可能是可能的:

    private void sendHandshakeRequest(String key) throws IOException{
    
            pw.print("Upgrade: websocket" + LINE_SEPARATOR);
            pw.print("Connection: Upgrade" + LINE_SEPARATOR);
            pw.print("Sec-WebSocket-Key: " + key + LINE_SEPARATOR);
            pw.print("Sec-WebSocket-Protocol: mqttv3.1" + LINE_SEPARATOR);
            pw.print("Sec-WebSocket-Version: 13" + LINE_SEPARATOR);
    
            // TODO add the header with your token here
    

    由于方法是private,并且类在internal包中,你别无选择,只能编译你自己的自定义版本的Paho库。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-30
      • 2016-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多