简体   繁体   中英

WebSocket SSL in JAVA

I have successfully established a WebSocket connection between a Client and the Server using this libraries:

  • Client: github.com/TakahikoKawasaki/nv-websocket-client
  • Server: github.com/TooTallNate/Java-WebSocket

Now I'm going to encrypt this connection whit SSL, but I haven't understand how I have to do to do this. In particular I've seen this example ( https://github.com/TooTallNate/Java-WebSocket/blob/master/src/main/example/SSLServerExample.java included in Java-WebSocket 1.3.0) where it require a KEYPASSWORD and a STOREPASSWORD, what are they? Instead in the other library (the client) it is not clear precisely how I should do... Thanks in advance!

In the case ofnv-websocket-client :

Replace ws: with wss: . For example, if the endpoint of your server is ws ://example.com/abc , change it to wss ://example.com/abc . In most cases, all you have to do is it.

In some cases, special setup for SSL is required. In such a case, use either of the following methods.

  • WebSocketFactory.setSSLContext(SSLContext)
  • WebSocketFactory.setSSLSocketFactory(SocketFactory)

See "Create WebSocketFactory" in README.md of nv-websocket-client and the JavaDoc for details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM