AzureRelayReceiver Component
Properties Methods Events Configuration Settings Errors
An Azure Relay Service listener to accept and communicate with clients.
Syntax
IPWorksMQ.Azurerelayreceiver
Remarks
The AzureRelayReceiver component implements the listener role in the Azure Relay service. The component 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 component will immediately attempt to make a connection to the Azure Relay Service and begin listening. The following properties are applicable when setting Listening:
- AccessKey (required)
- AccessKeyName (required)
- HybridConnection (required)
- NamespaceAddress (required)
- DefaultTimeout
- ForwardingHost
- ForwardingPort
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 DataToSend 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 component 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 component 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 component with short descriptions. Click on the links for further details.
AccessKey | The Shared Access Key. |
AccessKeyName | The Shared Access Key Name. |
Connected | Shows whether the component is connected. |
Connections | A collection of currently connected clients. |
DefaultTimeout | An initial timeout value to be used by incoming connections. |
Firewall | A set of properties related to firewall access. |
ForwardingHost | The address to which traffic will automatically be forwarded. |
ForwardingPort | The port to which traffic will automatically be forwarded. |
HybridConnection | The hybrid connection name. |
Listening | If True, connects to the Azure Relay Service and listens for incoming connections. |
LocalHost | The name of the local host or user-assigned IP interface through which connections are initiated or accepted. |
NamespaceAddress | The namespace address of the relay. |
Proxy | A set of properties related to proxy access. |
SSLAcceptServerCert | Instructs the component to unconditionally accept the server certificate that matches the supplied certificate. |
SSLCert | The certificate to be used during SSL negotiation. |
SSLServerCert | The server certificate for the last established connection. |
Method List
The following is the full list of the methods of the component with short descriptions. Click on the links for further details.
config | Sets or retrieves a configuration setting. |
disconnect | Disconnect the specified client. |
doEvents | Processes events from the internal message queue. |
interrupt | Interrupts a synchronous send to the remote host. |
send | Sends binary data to the client. |
sendFile | Send file to the remote host. |
sendHTTPResponse | Send the HTTP response. |
sendText | Sends text data to the client. |
shutdown | Shuts down the server. |
Event List
The following is the full list of the events fired by the component with short descriptions. Click on the links for further details.
Connected | Fired immediately after a connection completes (or fails). |
ConnectionConnected | Fired when a client has connected. |
ConnectionDataIn | Fired when data is received. |
ConnectionDisconnected | Fired when a WebSocket connection is disconnected. |
ConnectionError | Information about errors during data delivery. |
ConnectionReadyToSend | Fired when the component is ready to send data. |
ConnectionRequest | Fires when a WebSocket connection is requested. |
ConnectionStatus | Fired to indicate changes in connection state. |
Disconnected | Fired when a connection is closed. |
Error | Information about errors during data delivery. |
Header | Fired every time a header line comes in. |
HTTPRequest | Fires when an HTTP request is received. |
Log | Fires once for each log message. |
Redirect | Fired when a redirection is received from the server. |
SSLServerAuthentication | Fired after the server presents its certificate to the client. |
SSLStatus | Shows the progress of the secure connection. |
Configuration Settings
The following is a list of configuration settings for the component with short descriptions. Click on the links for further details.
AccessToken | Returns an access token for use outside of the components. |
AutoRenewThreshold | The threshold in seconds after which the token is renewed. |
AzureRelayKeepAliveTime | The inactivity period in seconds before a ping packet is sent to keep the connection alive. |
DiagnosticId | A diagnostic id used to enable end-to-end tracing. |
LogLevel | The level of detail that is logged. |
TokenValidity | The validity time in seconds of the access token. |
BufferMessage | Indicates whether or not the entire message is buffered before firing the DataIn event. |
DisconnectStatusCode | Specifies the status code when closing a connection. |
DisconnectStatusDescription | Specifies the message associated with the disconnect status code. |
MaxFrameSize | Specifies the maximum size of the outgoing message in bytes before fragmentation occurs. |
MessageLength[ConnectionId] | The length of the message (in bytes) when sending asynchronously. |
WaitForCloseResponse | Determines whether or not the component will forcibly close a connection. |
AllowedClients | A comma-separated list of host names or IP addresses that can access the component. |
BindExclusively | Whether or not the component considers a local port reserved for exclusive use. |
CloseStreamAfterTransfer | If true, the component will close the upload or download stream after the transfer. |
DefaultConnectionTimeout | The inactivity timeout applied to the SSL handshake. |
InBufferSize | The size in bytes of the incoming queue of the socket. |
KeepAliveInterval | The retry interval, in milliseconds, to be used when a TCP keep-alive packet is sent and no response is received. |
KeepAliveTime | The inactivity time in milliseconds before a TCP keep-alive packet is sent. |
MaxConnections | The maximum number of connections available. |
OutBufferSize | The size in bytes of the outgoing queue of the socket. |
TcpNoDelay | Whether or not to delay when sending packets. |
UseIPv6 | Whether to use IPv6. |
LogSSLPackets | Controls whether SSL packets are logged when using the internal security API. |
ReuseSSLSession | Determines if the SSL session is reused. |
SSLCACerts | A newline separated list of CA certificate to use during SSL client authentication. |
SSLCipherStrength | The minimum cipher strength used for bulk encryption. |
SSLContextProtocol | The protocol used when getting an SSLContext instance. |
SSLEnabledCipherSuites | The cipher suite to be used in an SSL negotiation. |
SSLEnabledProtocols | Used to enable/disable the supported security protocols. |
SSLEnableRenegotiation | Whether the renegotiation_info SSL extension is supported. |
SSLIncludeCertChain | Whether the entire certificate chain is included in the SSLServerAuthentication event. |
SSLNegotiatedCipher | Returns the negotiated ciphersuite. |
SSLNegotiatedCipherStrength | Returns the negotiated ciphersuite strength. |
SSLNegotiatedCipherSuite | Returns the negotiated ciphersuite. |
SSLNegotiatedKeyExchange | Returns the negotiated key exchange algorithm. |
SSLNegotiatedKeyExchangeStrength | Returns the negotiated key exchange algorithm strength. |
SSLNegotiatedProtocol | Returns the negotiated protocol version. |
SSLProvider | The name of the security provider to use. |
SSLServerCACerts | A newline separated list of CA certificate to use during SSL server certificate validation. |
SSLTrustManagerFactoryAlgorithm | The algorithm to be used to create a TrustManager through TrustManagerFactory. |
TLS12SignatureAlgorithms | Defines the allowed TLS 1.2 signature algorithms when UseInternalSecurityAPI is True. |
TLS12SupportedGroups | The supported groups for ECC. |
TLS13KeyShareGroups | The groups for which to pregenerate key shares. |
TLS13SignatureAlgorithms | The allowed certificate signature algorithms. |
TLS13SupportedGroups | The supported groups for (EC)DHE key exchange. |