/// <summary> /// Start up a session on the server side /// </summary> public void Accept() { TlsServerProtocol serverProtocol = new TlsServerProtocol(new SecureRandom()); TlsServer server = new TlsServer(_signingKeys, _clientKeys); // Make sure we do not startup a listing thread as the correct call is always made // byt the DTLS accept protocol. _stm = _client.GetStream(); serverProtocol.Accept(server); bool sleep = true; while (!server.HandshakeComplete) { sleep = true; if (_stm.DataAvailable) { byte[] data = new byte[1024]; int cbRead = _stm.Read(data, 0, data.Length); Array.Resize(ref data, cbRead); serverProtocol.OfferInput(data); sleep = false; } int cbToRead = serverProtocol.GetAvailableOutputBytes(); if (cbToRead != 0) { byte[] data = new byte[cbToRead]; int cbRead = serverProtocol.ReadOutput(data, 0, cbToRead); _stm.Write(data, 0, cbRead); sleep = false; } if (sleep) { Thread.Sleep(100); } } _tlsServer = serverProtocol; _authKey = server.AuthenticationKey; _stm.BeginRead(_buffer, 0, _buffer.Length, ReadCallback, this); }