 		private var incomingBuffer:ByteArray;
 		private var outgoingBuffer:ByteArray;
 		
+		private var tlsConfig:TLSConfig;
+		private var tlsSocket:TLSSocket;
+		
 		private var URIpathExcludedBitmap:URIEncodingBitmap =
 			new URIEncodingBitmap(URI.URIpathEscape);
 		

			_origin = origin;
			this.timeout = timeout;
			this.handshakeTimeout = timeout;
			if (socket) {
				this.socket = socket;
			}
			else {
				this.socket = new Socket();
			}
			init();
		}
		
		private function init():void {
			parseUrl();
			this.socket.timeout = timeout;
			this.socket.endian = Endian.BIG_ENDIAN;
			this.socket.addEventListener(Event.CONNECT, handleSocketConnect);
			this.socket.addEventListener(Event.CLOSE, handleSocketClose);
			this.socket.addEventListener(ProgressEvent.SOCKET_DATA, handleSocketData);
			this.socket.addEventListener(IOErrorEvent.IO_ERROR, handleSocketIOError);
			this.socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handleSocketSecurityError);
			
			closeTimer = new Timer(closeTimeout, 1);
			closeTimer.addEventListener(TimerEvent.TIMER, handleCloseTimer);
			
			handshakeTimer = new Timer(handshakeTimeout, 1);
			handshakeTimer.addEventListener(TimerEvent.TIMER, handleHandshakeTimer);
			
			_readyState = WebSocketState.INIT;
		}

			if (debug) {
				logger("Socket Connected");
			}
			if (secure) {
				if (debug) {
					logger("starting SSL/TLS");
				}
				tlsSocket.startTLS(rawSocket, _host, tlsConfig);
			}
			socket.endian = Endian.BIG_ENDIAN;
			sendHandshake();
		}
		
