public DtlsWrapper(Client client, Action <Client, byte[]> sendCallback) { _client = client; _sendCallback = sendCallback; _bio = OpenSsl.BIO_new(_bioMeth); if (_bio == IntPtr.Zero) { throw new Exception("Cannot allocate exchange BIO"); } _ssl = OpenSsl.SSL_new(_sslCtx); if (_ssl == IntPtr.Zero) { OpenSsl.BIO_free(_bio); throw new Exception("Cannot initialize ssl"); } OpenSsl.SSL_set_bio(Ssl, _bio, _bio); _handle = GCHandle.Alloc(this, GCHandleType.Normal); OpenSsl.BIO_set_data(_bio, GCHandle.ToIntPtr(_handle)); _packets = new BlockingCollection <byte[]>(); }