 		private var _secure:Boolean;
 		private var _origin:String;
 		
+		private var rawSocket:Socket;
 		private var socket:Socket;
 		private var timeout:uint;
 		

			logger(text);
		};
		
		public function WebSocket(uri:String, origin:String, protocol:String = null, timeout:uint = 10000, socket:Socket = null)
		{
			super(null);
			_uri = new URI(uri);

			_origin = origin;
			this.timeout = timeout;
			this.handshakeTimeout = timeout;
			init();
		}
		
		private function init():void {
			parseUrl();

			closeTimer = new Timer(closeTimeout, 1);
			closeTimer.addEventListener(TimerEvent.TIMER, handleCloseTimer);
			
			handshakeTimer = new Timer(handshakeTimeout, 1);
			handshakeTimer.addEventListener(TimerEvent.TIMER, handleHandshakeTimer);
			
			rawSocket = socket = new Socket();
			socket.timeout = timeout;
			
			if (secure) {
				tlsConfig = new TLSConfig(TLSEngine.CLIENT,
										  null, null, null, null, null,
										  TLSSecurityParameters.PROTOCOL_VERSION);
				tlsConfig.trustAllCertificates = true;
				tlsConfig.ignoreCommonNameMismatch = true;
				socket = tlsSocket = new TLSSocket();
			}
			
			rawSocket.addEventListener(Event.CONNECT, handleSocketConnect);
			rawSocket.addEventListener(Event.CLOSE, handleSocketClose);
			rawSocket.addEventListener(IOErrorEvent.IO_ERROR, handleSocketIOError);
			rawSocket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handleSocketSecurityError);
			
			socket.addEventListener(ProgressEvent.SOCKET_DATA, handleSocketData);
			
			_readyState = WebSocketState.INIT;
		}
