Skip to content

Commit fbc52ec

Browse files
committed
Add true WSS support to WebSocketClient
1 parent d110e5a commit fbc52ec

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎src/main/java/org/java_websocket/client/WebSocketClient.java‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
import java.util.Map;
4040
import java.util.concurrent.CountDownLatch;
4141

42+
import javax.net.ssl.SSLContext;
43+
import javax.net.ssl.SSLSocketFactory;
44+
4245
import org.java_websocket.AbstractWebSocket;
4346
import org.java_websocket.WebSocket;
4447
import org.java_websocket.WebSocketImpl;
@@ -226,7 +229,14 @@ public void sendPing() throws NotYetConnectedException {
226229
public void run() {
227230
try {
228231
if( socket == null ) {
229-
socket = new Socket( proxy );
232+
if (this.uri.getScheme().equals("wss")) {
233+
SSLContext sslContext = SSLContext.getInstance("TLS");
234+
sslContext.init(null, null, null);
235+
SSLSocketFactory factory = sslContext.getSocketFactory();
236+
socket = factory.createSocket();
237+
} else {
238+
socket = new Socket( proxy );
239+
}
230240
} else if( socket.isClosed() ) {
231241
throw new IOException();
232242
}

0 commit comments

Comments
 (0)