AzureRelayReceiver Class

Properties   Methods   Events   Configuration Settings   Errors  

An Azure Relay Service listener to accept and communicate with clients.

Syntax

AzureRelayReceiver

Remarks

The AzureRelayReceiver class implements the listener role in the Azure Relay service. The class will connect to the server and listen for incoming connections. Once a connection is established data can be exchange freely in both directions allowing a flexible messaging environment.

Authenticating and Listening

Authentication to Azure Relay is performed using the Shared Access Key Name and Shared Access Key created from the Azure portal for the Relay. To begin listening for incoming connections set Listening to True.

When set to True the class will immediately attempt to make a connection to the Azure Relay Service and begin listening. The following properties are applicable when setting Listening:

To stop listening set Listening to False. To shutdown the server including existing connections call Shutdown.

Handling Connections

When a connection is made the ConnectionRequest event fires with information about the connecting client. From within this event the client connection may be accepted (default) or rejected.

If the client connection is accepted the ConnectionConnected and ConnectionReadyToSend events fire when the connection completes and is ready to send and receive data.

When data is received from the client the ConnectionDataIn event fires with the received data.

To send data to the client set AzureRelayConnectionDataToSend or call Send, SendFile, or SendText.

When the client disconnects the ConnectionDisconnected event fires. To initiate the client disconnection call Disconnect.

Handling HTTP Connections

Azure Relay also supports HTTP connections which follow a request/response model. When an HTTP request is received the HTTPRequest event fires with information about the request including the request body. Save the ConnectionId value obtained within HTTPRequest for use with SendHTTPResponse.

To send a HTTP response call SendHTTPResponse with the ConnectionId, status code and description, and any response day to be sent back to the client.

Forwarding Connections

The class supports forwarding incoming connection to a separate destination. This functionality allows AzureRelayReceiver to act as a proxy for incoming requests. When ForwardingHost and ForwardingPort are set anytime a connection is made the class will establish a separate connection to the ForwardingHost and forward all incoming traffic. Responses from the ForwardingHost are then automatically sent back over the connection.

When connection forwarding is used no special steps are needed to send or receive data. Data flows freely between the connected client and the ForwardingHost.

Note: Forwarding is not supported for HTTP requests.

Code Example (WebSockets)


Azurerelayreceiver listener = new Azurerelayreceiver();
listener.AccessKey = "9oKRDwjl0s440MlLUi4qHxDL34j1FS6K3t5TRoJ216c=";
listener.AccessKeyName = "RootManageSharedAccessKey";
listener.NamespaceAddress = "myrelay.servicebus.windows.net";
listener.HybridConnection = "hc1";

listener.OnConnectionRequest += (s, e) =>
{
  Console.WriteLine("Connection Request From: " + e.RemoteAddress + ":" + e.RemotePort);
  e.Accept = true;
};

listener.OnConnectionReadyToSend += (s, e) =>
{
  Console.WriteLine("Connection [" + e.ConnectionId + "] connected and ready to send and receive.");
};

listener.OnConnectionDataIn += (s, e) =>
{
  Console.WriteLine("Received data from " + e.ConnectionId + ": " + e.Text);
  //echo the data back
  listener.SendText(e.ConnectionId, e.Text);
  Console.WriteLine("Echoed received data back");
};

listener.Listening = true;

while (true)
  listener.DoEvents();

Code Example (HTTP)


Azurerelaylistener listener = new Azurerelaylistener();
listener.AccessKey = "9oKRDwjl0s440MlLUi4qHxDL34j1FS6K3t5TRoJ216c=";
listener.AccessKeyName = "RootManageSharedAccessKey";
listener.NamespaceAddress = "myrelay.servicebus.windows.net";
listener.HybridConnection = "hc1";

listener.OnHTTPRequest += (s, e) => {
  Console.WriteLine("HTTP Request from " + e.RemoteAddress + ":" + e.RemotePort);
  Console.WriteLine("HTTP Method: " + e.RequestMethod);
  Console.WriteLine("HTTP Request: " + e.RequestData);
  myConnectionId = e.ConnectionId;
};

//Send a response using the ConnectionId value from the HTTPRequest event
listener.SendHTTPResponse(myConnectionId, 200, "OK", myResponseBody);

Property List


The following is the full list of the properties of the class with short descriptions. Click on the links for further details.

AccessKeyThe Shared Access Key.
AccessKeyNameThe Shared Access Key Name.
ConnectedShows whether the class is connected.
AzureRelayConnectionCountThe number of records in the AzureRelayConnection arrays.
AzureRelayConnectionAcceptDataSetting this property to False, temporarily disables data reception (and the ConnectionDataIn event) on the connection.
AzureRelayConnectionAddressThis property holds the rendezvous URL to which the connection specific websocket connection will be made.
AzureRelayConnectionBytesSentThis property shows how many bytes were sent after the last assignment to DataToSend .
AzureRelayConnectionConnectedThis property is used to disconnect individual connections and/or show their status.
AzureRelayConnectionConnectHeadersA JSON object containing the HTTP headers that have been supplied by the sender to the Azure Relay service.
AzureRelayConnectionConnectionIdThis property contains an identifier generated by the class to identify each connection.
AzureRelayConnectionDataFormatThe format of the data being sent.
AzureRelayConnectionDataToSendThis property contains a string of data to be sent to the remote host.
AzureRelayConnectionExtensionsThe WebSocket extensions sent by the client in the initial WebSocket connection request.
AzureRelayConnectionHostThe Host header value of the connected client.
AzureRelayConnectionIdThis property holds the Id of the connection.
AzureRelayConnectionReadyToSendIndicates whether the class is ready to send data.
AzureRelayConnectionRemoteAddressThis property holds the IP address of the connecting client.
AzureRelayConnectionRemotePortThis property holds the port of the connecting client.
AzureRelayConnectionSubProtocolsThe subprotocols (application-level protocols layered over the WebSocket Protocol) sent by the client in the initial WebSocket connection request.
AzureRelayConnectionTimeoutThis property specifies a timeout for the class.
DefaultTimeoutAn initial timeout value to be used by incoming connections.
FirewallAutoDetectThis property tells the class whether or not to automatically detect and use firewall system settings, if available.
FirewallTypeThis property determines the type of firewall to connect through.
FirewallHostThis property contains the name or IP address of firewall (optional).
FirewallPasswordThis property contains a password if authentication is to be used when connecting through the firewall.
FirewallPortThis property contains the TCP port for the firewall Host .
FirewallUserThis property contains a user name if authentication is to be used connecting through a firewall.
ForwardingHostThe address to which traffic will automatically be forwarded.
ForwardingPortThe port to which traffic will automatically be forwarded.
HybridConnectionThe hybrid connection name.
ListeningIf True, connects to the Azure Relay Service and listens for incoming connections.
LocalHostThe name of the local host or user-assigned IP interface through which connections are initiated or accepted.
NamespaceAddressThe namespace address of the relay.
ProxyAuthSchemeThis property is used to tell the class which type of authorization to perform when connecting to the proxy.
ProxyAutoDetectThis property tells the class whether or not to automatically detect and use proxy system settings, if available.
ProxyPasswordThis property contains a password if authentication is to be used for the proxy.
ProxyPortThis property contains the TCP port for the proxy Server (default 80).
ProxyServerIf a proxy Server is given, then the HTTP request is sent to the proxy instead of the server otherwise specified.
ProxySSLThis property determines when to use SSL for the connection to the proxy.
ProxyUserThis property contains a user name, if authentication is to be used for the proxy.
SSLAcceptServerCertEncodedThe certificate (PEM/base64 encoded).
SSLCertEncodedThe certificate (PEM/base64 encoded).
SSLCertStoreThe name of the certificate store for the client certificate.
SSLCertStorePasswordIf the certificate store is of a type that requires a password, this property is used to specify that password in order to open the certificate store.
SSLCertStoreTypeThe type of certificate store for this certificate.
SSLCertSubjectThe subject of the certificate used for client authentication.
SSLServerCertEncodedThe certificate (PEM/base64 encoded).

Method List


The following is the full list of the methods of the class with short descriptions. Click on the links for further details.

ConfigSets or retrieves a configuration setting.
DisconnectDisconnect the specified client.
DoEventsProcesses events from the internal message queue.
InterruptInterrupts a synchronous send to the remote host.
SendSends binary data to the client.
SendFileSend file to the remote host.
SendHTTPResponseSend the HTTP response.
SendTextSends text data to the client.
ShutdownShuts down the server.

Event List


The following is the full list of the events fired by the class with short descriptions. Click on the links for further details.

ConnectedFired immediately after a connection completes (or fails).
ConnectionConnectedFired when a client has connected.
ConnectionDataInFired when data is received.
ConnectionDisconnectedFired when a WebSocket connection is disconnected.
ConnectionErrorInformation about errors during data delivery.
ConnectionReadyToSendFired when the class is ready to send data.
ConnectionRequestFires when a WebSocket connection is requested.
ConnectionStatusFired to indicate changes in connection state.
DisconnectedFired when a connection is closed.
ErrorInformation about errors during data delivery.
HeaderFired every time a header line comes in.
HTTPRequestFires when an HTTP request is received.
LogFires once for each log message.
RedirectFired when a redirection is received from the server.
SSLServerAuthenticationFired after the server presents its certificate to the client.
SSLStatusShows the progress of the secure connection.

Configuration Settings


The following is a list of configuration settings for the class with short descriptions. Click on the links for further details.

AccessTokenReturns an access token for use outside of the classes.
AutoRenewThresholdThe threshold in seconds after which the token is renewed.
AzureRelayKeepAliveTimeThe inactivity period in seconds before a ping packet is sent to keep the connection alive.
DiagnosticIdA diagnostic id used to enable end-to-end tracing.
LogLevelThe level of detail that is logged.
TokenValidityThe validity time in seconds of the access token.
BufferMessageIndicates whether or not the entire message is buffered before firing the DataIn event.
DisconnectStatusCodeSpecifies the status code when closing a connection.
DisconnectStatusDescriptionSpecifies the message associated with the disconnect status code.
MaxFrameSizeSpecifies the maximum size of the outgoing message in bytes before fragmentation occurs.
MessageLength[ConnectionId]The length of the message (in bytes) when sending asynchronously.
WaitForCloseResponseDetermines whether or not the class will forcibly close a connection.
AllowedClientsA comma-separated list of host names or IP addresses that can access the class.
BindExclusivelyWhether or not the class considers a local port reserved for exclusive use.
DefaultConnectionTimeoutThe inactivity timeout applied to the SSL handshake.
InBufferSizeThe size in bytes of the incoming queue of the socket.
KeepAliveIntervalThe retry interval, in milliseconds, to be used when a TCP keep-alive packet is sent and no response is received.
KeepAliveTimeThe inactivity time in milliseconds before a TCP keep-alive packet is sent.
MaxConnectionsThe maximum number of connections available.
OutBufferSizeThe size in bytes of the outgoing queue of the socket.
TcpNoDelayWhether or not to delay when sending packets.
UseIPv6Whether to use IPv6.
LogSSLPacketsControls whether SSL packets are logged when using the internal security API.
OpenSSLCADirThe path to a directory containing CA certificates.
OpenSSLCAFileName of the file containing the list of CA's trusted by your application.
OpenSSLCipherListA string that controls the ciphers to be used by SSL.
OpenSSLPrngSeedDataThe data to seed the pseudo random number generator (PRNG).
ReuseSSLSessionDetermines if the SSL session is reused.
SSLCACertsA newline separated list of CA certificate to use during SSL client authentication.
SSLCheckCRLWhether to check the Certificate Revocation List for the server certificate.
SSLCipherStrengthThe minimum cipher strength used for bulk encryption.
SSLEnabledCipherSuitesThe cipher suite to be used in an SSL negotiation.
SSLEnabledProtocolsUsed to enable/disable the supported security protocols.
SSLEnableRenegotiationWhether the renegotiation_info SSL extension is supported.
SSLIncludeCertChainWhether the entire certificate chain is included in the SSLServerAuthentication event.
SSLNegotiatedCipherReturns the negotiated ciphersuite.
SSLNegotiatedCipherStrengthReturns the negotiated ciphersuite strength.
SSLNegotiatedCipherSuiteReturns the negotiated ciphersuite.
SSLNegotiatedKeyExchangeReturns the negotiated key exchange algorithm.
SSLNegotiatedKeyExchangeStrengthReturns the negotiated key exchange algorithm strength.
SSLNegotiatedProtocolReturns the negotiated protocol version.
SSLProviderThe name of the security provider to use.
SSLSecurityFlagsFlags that control certificate verification.
SSLServerCACertsA newline separated list of CA certificate to use during SSL server certificate validation.
TLS12SignatureAlgorithmsDefines the allowed TLS 1.2 signature algorithms when UseInternalSecurityAPI is True.
TLS12SupportedGroupsThe supported groups for ECC.
TLS13KeyShareGroupsThe groups for which to pregenerate key shares.
TLS13SignatureAlgorithmsThe allowed certificate signature algorithms.
TLS13SupportedGroupsThe supported groups for (EC)DHE key exchange.

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks MQ 2020 Qt Edition - Version 20.0 [Build 8155]