 			case Stream.Event.openCompleted:
 				handleOpenning()
 			case Stream.Event.errorOccurred:
-				handleError(error: stream.streamError!)
+				disconnect(withError: stream.streamError)
 			default: break
 		}
 	}

		delegateQueue?.async {
			self.delegate?.socketDidConnect(self)
		}
	}
	
	private func handleError(error: Error) {
		if case .closed = status {
			return
		}
		status = .closed(error)
		delegateQueue?.async {
			self.delegate?.socket(self, didFailWithError: error)
		}
		disconnect(withError: error)
	}
	
	private func setupSocketsSecurity() {

			case Stream.Event.openCompleted:
				handleOpenning()
			case Stream.Event.errorOccurred:
				disconnect(withError: stream.streamError)
			case Stream.Event.hasBytesAvailable:
				let data = inputStream!.readAllData()
				delegateQueue?.async {
