2017-05-31 52 views
0

我有一個mqtt客戶端連接到一個經紀人。 我的經紀人攔截連接以從中獲取令牌並執行一些操作。 我想連接時發送一個令牌作爲查詢參數。發送查詢參數與連接apache帕霍websocket客戶端

我的客戶端連接是這樣的:

 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); 

我怎樣才能做到這一點?有人能幫助我嗎?

回答

0

如果您修改方法sendHandshakeRequest在類WebSocketHandshake這可能是可能的:

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圖書館的版本。

相關問題