/// <summary> /// Establishes a connection with a broker using the provided user auths /// /// </summary> /// <param name="host">Host name on which a broker is deployed</param> /// <param name="port">Broker port </param> /// <param name="virtualHost">virtual host name</param> /// <param name="username">User Name</param> /// <param name="password">Password</param> /// <param name="mechanism">SASL authentication mechanism, possible values: PLAIN, EXTERNAL, DIGEST-MD5, ANONYMOUS</param> public void Connect(String host, int port, String virtualHost, String username, String password, String mechanism) { _log.Debug(String.Format("Client Connecting to host {0}; port {1}; virtualHost {2}; username {3}; mechanism {4}", host, port, virtualHost, username, mechanism)); ClientConnectionDelegate connectionDelegate = new ClientConnectionDelegate(this, username, password, mechanism); ManualResetEvent negotiationComplete = new ManualResetEvent(false); connectionDelegate.SetCondition(negotiationComplete); connectionDelegate.VirtualHost = virtualHost; _conn = IoTransport.Connect(host, port, connectionDelegate); _conn.Send(new ProtocolHeader(1, 0, 10)); negotiationComplete.WaitOne(); if (connectionDelegate.Exception != null) throw connectionDelegate.Exception; connectionDelegate.SetCondition(null); }
public static Connection Connect(String host, int port, String mechanism, X509Certificate certificate, bool rejectUntrusted, Client client) { ClientConnectionDelegate connectionDelegate = new ClientConnectionDelegate(client, string.Empty, string.Empty, mechanism); ManualResetEvent negotiationComplete = new ManualResetEvent(true); connectionDelegate.SetCondition(negotiationComplete); connectionDelegate.VirtualHost = string.Empty; IIoTransport transport = new IoSSLTransport(host, port, certificate, rejectUntrusted, connectionDelegate); Connection _conn = transport.Connection; _conn.Send(new ProtocolHeader(1, 0, 10)); negotiationComplete.WaitOne(); if (connectionDelegate.Exception != null) throw connectionDelegate.Exception; connectionDelegate.SetCondition(null); return _conn; }
/// <summary> /// Establishes a connection with a broker using the provided user auths /// /// </summary> /// <param name="host">Host name on which a broker is deployed</param> /// <param name="port">Broker port </param> /// <param name="virtualHost">virtual host name</param> /// <param name="username">User Name</param> /// <param name="password">Password</param> /// <param name="mechanism">SASL authentication mechanism, possible values: PLAIN, EXTERNAL, DIGEST-MD5, ANONYMOUS</param> public void Connect(String host, int port, String virtualHost, String username, String password, String mechanism) { _log.Debug(String.Format("Client Connecting to host {0}; port {1}; virtualHost {2}; username {3}; mechanism {4}", host, port, virtualHost, username, mechanism)); ClientConnectionDelegate connectionDelegate = new ClientConnectionDelegate(this, username, password, mechanism); ManualResetEvent negotiationComplete = new ManualResetEvent(false); connectionDelegate.SetCondition(negotiationComplete); connectionDelegate.VirtualHost = virtualHost; _conn = IoTransport.Connect(host, port, connectionDelegate); _conn.Send(new ProtocolHeader(1, 0, 10)); negotiationComplete.WaitOne(); if (connectionDelegate.Exception != null) { throw connectionDelegate.Exception; } connectionDelegate.SetCondition(null); }