Skip to content

Commit a5b0a4e

Browse files
committed
Fixed an issue where although sockets would connect no handshake would
take place and data transfer would throw exceptions
1 parent a952190 commit a5b0a4e

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

ws4py/client/tornadoclient.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22
import socket
33
from urlparse import urlsplit
4+
import ssl
45

56
from tornado import iostream, escape
67
from ws4py.client import WebSocketBaseClient
@@ -11,14 +12,18 @@
1112
class TornadoWebSocketClient(WebSocketBaseClient):
1213
def __init__(self, url, protocols=None, extensions=None, io_loop=None):
1314
WebSocketBaseClient.__init__(self, url, protocols, extensions)
14-
self.io = iostream.IOStream(self.sock, io_loop)
15+
parts = urlsplit(self.url)
16+
if parts.scheme == "wss":
17+
self.sock = ssl.wrap_socket(self.sock,
18+
do_handshake_on_connect=False)
19+
self.io = iostream.SSLIOStream(self.sock, io_loop)
20+
else:
21+
self.io = iostream.IOStream(self.sock, io_loop)
1522
self.sender = self.io.write
1623
self.io_loop = io_loop
1724

1825
def connect(self):
1926
parts = urlsplit(self.url)
20-
if parts.scheme == "wss":
21-
self.io = iostream.SSLIOStream(self.sock, self.io_loop)
2227
host, port = parts.netloc, 80
2328
if ':' in host:
2429
host, port = parts.netloc.split(':')

0 commit comments

Comments
 (0)