2017-06-12 289 views
0

讀者文摘版本: 首次寫入websocket客戶端。使用Eclipse的Java 1.8。雖然我的工作場所內部網絡得到一個握手錯誤異常和WebSocket的日誌信息,告訴我:Websocket客戶端在升級時發生hanshake錯誤426

< Session 1c61123c-aa5f-4e59-a49d-b5d3c77c0bbd [598 ms]: Received handshake response: 
< 426 
< connection: Keep-Alive 
< content-length: 29 
< content-type: text/plain; charset=utf-8 
< date: Mon, 12 Jun 2017 16:40:04 GMT 
< server: nginx 

    Exception in thread "main" java.lang.RuntimeException: javax.websocket.DeploymentException: Handshake error. 
     at webSocketExample.WebsocketClientEndpoint.<init>(WebsocketClientEndpoint.java:60) 

詳情: 當我連接到我的內部工作網絡,並嘗試做一個WebSocket連接我最初得到連接,但然後我發送一個TCP重置。如果我將代碼放在筆記本電腦上,並通過不同的網絡(如我的家鄉康卡斯特連接)進行連接,則會建立連接,並從服務器接收初始數據響應。然後,我拿起筆記本電腦,將其連接到我的內部工作網絡,然後再回到握手錯誤。

我一直無法通過我的內部安全團隊來解決它,因爲我們不在這裏做websocket開發,所以知識庫有點欠缺。

我在從我的main調用這個例程之前設置了我的代理。已經證實,我正在連接到服務器,但後來我發送重置。這裏是我執行的代碼:

try { 

     System.setProperty("javax.net.debug", "all"); 

     ClientManager client = ClientManager.createClient(); 

     final SSLContextConfigurator defaultConfig = new SSLContextConfigurator(); 

     defaultConfig.retrieve(System.getProperties()); 
     SSLEngineConfigurator sslEngine = new SSLEngineConfigurator(defaultConfig, true, false, false); 

     client.getProperties().put(ClientProperties.SSL_ENGINE_CONFIGURATOR, sslEngine); 
     client.getProperties().put(ClientProperties.LOG_HTTP_UPGRADE, true); 

     client.connectToServer(new Endpoint() { 
      @Override 
      public void onOpen(Session session, EndpointConfig config) { 
       session.addMessageHandler(new MessageHandler.Whole<String>() { 
        @Override 
        public void onMessage(String message) { 
         System.out.println(message); 
        } 
       }); 
      } 
     }, ClientEndpointConfig.Builder.create().build(), 
       new URI("wss://api.sandbox.gemini.com/v1/marketdata/BTCUSD")); 

    } catch (Exception e) { 
     throw new RuntimeException(e); 
    } 

我看了所有的文章/問題/答案,我已經能夠找到,但沒有拿出任何東西。由於我們的安全性非常嚴格,所以我對自己在網絡上的行爲有些限制,但是如果遇到問題,我可以與我的安全團隊一起尋找答案。

我認爲它必須是我的工作網絡和代理的內部,但我一直無法解決它。此外,這是從連接和錯誤報告日誌信息的最後一部分:

軟墊明文解密後:LEN = 170

0000: 48 54 54 50 2F 31 2E 31 20 34 32 36 20 55 70 67 HTTP/1.1 426 Upg 
0010: 72 61 64 65 20 52 65 71 75 69 72 65 64 0D 0A 44 rade Required..D 
0020: 61 74 65 3A 20 4D 6F 6E 2C 20 31 32 20 4A 75 6E ate: Mon, 12 Jun 
0030: 20 32 30 31 37 20 31 36 3A 35 30 3A 32 35 20 47 2017 16:50:25 G 
0040: 4D 54 0D 0A 53 65 72 76 65 72 3A 20 6E 67 69 6E MT..Server: ngin 
0050: 78 0D 0A 43 6F 6E 6E 65 63 74 69 6F 6E 3A 20 4B x..Connection: K 
0060: 65 65 70 2D 41 6C 69 76 65 0D 0A 43 6F 6E 74 65 eep-Alive..Conte 
0070: 6E 74 2D 54 79 70 65 3A 20 74 65 78 74 2F 70 6C nt-Type: text/pl 
0080: 61 69 6E 3B 20 63 68 61 72 73 65 74 3D 75 74 66 ain; charset=utf 
0090: 2D 38 0D 0A 43 6F 6E 74 65 6E 74 2D 4C 65 6E 67 -8..Content-Leng 
00A0: 74 68 3A 20 32 39 0D 0A 0D 0A     th: 29.... 
[Raw read (bb)]: length = 58 
0000: 17 03 03 00 35 EC 0F C3 40 0D 18 B4 7B 53 C6 2D [email protected] 
0010: F5 83 29 72 15 51 AC 31 8F 86 52 C9 3C 98 BB F8 ..)r.Q.1..R.<... 
0020: 94 4A D7 3A 6E 17 8C 75 9E 58 25 0B AE B5 2F 13 .J.:n..u.X%.../. 
0030: 8C 44 29 94 2F 4A 46 18 C9 1A     .D)./JF... 
Padded plaintext after DECRYPTION: len = 29 
0000: 55 70 67 72 61 64 65 20 74 6F 20 57 65 62 53 6F Upgrade to WebSo 
0010: 63 6B 65 74 20 72 65 71 75 69 72 65 64   cket required 
> Session 6f920826-4b05-47bd-8cad-212038ff9fad [86 ms]: Sending handshake request: 
> GET wss://api.sandbox.gemini.com/v1/marketdata/BTCUSD 
> Connection: Upgrade 
> Host: api.sandbox.gemini.com 
> Origin: api.sandbox.gemini.com 
> Sec-WebSocket-Key: nkgv7uk/bPSKBiOz5T/Bdg== 
> Sec-WebSocket-Version: 13 
> Upgrade: websocket 

< Session 6f920826-4b05-47bd-8cad-212038ff9fad [600 ms]: Received handshake response: 
< 426 
< connection: Keep-Alive 
< content-length: 29 
< content-type: text/plain; charset=utf-8 
< date: Mon, 12 Jun 2017 16:50:25 GMT 
< server: nginx 

如果你走到這一步,謝謝...

從我的網絡團隊添加嗅探器信息: 您將建立一個連接Pkt 263,您正在通過代理服務器mcweb-a 170.137.249.117。然後你傳輸數據。復位在280的Pkt

enter image description here

回答

0

發送萬一有人遇到此。這個問題與我的代理服務器有關。我們必須將特定端點添加爲可允許的,以避免一些安全檢查。