Class NgWebSocketClient
Class for a Web Socket Client that can be used for NG9-1-1 applications.
Inherited Members
Namespace: NgWebSockets
Assembly: Ng911Lib.dll
Syntax
public class NgWebSocketClient
Constructors
| Edit this page View SourceNgWebSocketClient(X509Certificate2, string, RemoteCertificateValidationCallback)
Constructs a new Web Socket client object. After calling this constructor, hook the MessageReceived event, then call Connect().
Declaration
public NgWebSocketClient(X509Certificate2 clientCertificate, string strSubProtocol, RemoteCertificateValidationCallback validationCallback)
Parameters
Type | Name | Description |
---|---|---|
X509Certificate2 | clientCertificate | Client X.509 certificate to use if mutual authentication is required (i.e., the server requires a client certificate). May be null if mutual authentication is not required. |
string | strSubProtocol | Sets the sub-protocol for the web socket connection. If not null, then the Sec-WebSocket-Protocol HTTP header will be set to this value. May be null if a sub-protocol is not being used. |
RemoteCertificateValidationCallback | validationCallback | Specifies an application provided callback function that will be called to valicate the web socket server's X.509 certificate. May be null if extended certificate validation is not required. If null, then this class will use its own validation callback function that accepts all server certificates. |
Methods
| Edit this page View SourceClose()
Closes the web socket connection in an orderly manner.
Declaration
public void Close()
Connect(string)
Connects to the web socket server. Messages may be sent and received if the connection was successful.
Declaration
public Task<bool> Connect(string strUrl)
Parameters
Type | Name | Description |
---|---|---|
string | strUrl | URL of the web socket server to connect to. The URL scheme must be wss: or ws: |
Returns
Type | Description |
---|---|
Task<bool> | Returns true if successful or false if the connection attempt failed. |
SendMessage(string)
Sends an arbitrally long message as a string to the server. This method is thread-safe, i.e., send operations are synchronized.
Declaration
public Task<bool> SendMessage(string strMessage)
Parameters
Type | Name | Description |
---|---|---|
string | strMessage | Message to be sent. |
Returns
Type | Description |
---|---|
Task<bool> | Returns true if successful. Returns false if an error occurred, probably because the connection to the server is broken. |
Events
| Edit this page View SourceMessageReceived
Event that is fired when a complete message is received. It is OK to call the SendMessage() method from within the event handler of this event, but don't hold onto a reference to it and use it outside of the event handler.
Declaration
public event WebSocketMessageReceived MessageReceived
Event Type
Type | Description |
---|---|
WebSocketMessageReceived |