public static TlsClientProtocol ConnectPskTlsClientNonBlocking(string identity, byte[] psk) { try { SimplePskIdentity pskIdentity = new SimplePskIdentity(identity, psk); PskTlsClient2 pskTlsClient = new PskTlsClient2(pskIdentity); TlsClientProtocol protocol = new TlsClientProtocol(new SecureRandom()); protocol.Connect(pskTlsClient); return(protocol); } catch (Exception ex) { Console.WriteLine("Exception in TLS protocol connnection '{0}'", ex.Message); throw ex; } }
public static TlsClientProtocol ConnectPskTlsClientNonBlocking(this TcpClient client, string identity, byte[] psk) { try { SimplePskIdentity pskIdentity = new SimplePskIdentity(identity, psk); PskTlsClient2 pskTlsClient = new PskTlsClient2(pskIdentity); TlsClientProtocol protocol = new TlsClientProtocol(new SecureRandom()); protocol.Connect(pskTlsClient); return(protocol); } catch (AggregateException ae) { string msg = String.Format("AggregateException in TLS protocol connnection '{0}'", ae.Flatten().InnerException.Message); Console.WriteLine(msg); throw new Exception(msg, ae.Flatten().InnerException); } catch (Exception ex) { Console.WriteLine("Exception in TLS protocol connnection '{0}'", ex.Message); throw ex; } }