 
 				headersTerminatorIndex = serverHandshakeResponse.search(/\r?\n\r?\n/);
 			}
+			if (headersTerminatorIndex === -1) {
+				return;
+			}
 
 			if (debug) {
 				logger("Server Response Headers:\n" + serverHandshakeResponse);

	import com.adobe.crypto.SHA1;
	import com.adobe.net.URI;
	import com.adobe.net.URIEncodingBitmap;
	import com.wirelust.as3zlib.Deflate;
	import com.wirelust.as3zlib.Inflate;
	import com.wirelust.as3zlib.JZlib;

				}
				zstreamOut.next_out.position = 0;
				socket.writeBytes(zstreamOut.next_out, 0, zstreamOut.next_out.length);
				socket.flush();
				zstreamOut.next_in.clear();
				zstreamOut.next_out.clear();
			}
			else {
				socket.writeBytes(data, 0, data.bytesAvailable);
				socket.flush();
				data.clear();
			}
		}
