Class WebSocketBehavior
Exposes the methods and properties used to define the behavior of a WebSocket service
provided by the
WebSocketServer or
.
Inheritance
System.Object
WebSocketBehavior
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Assembly: Mars.Common.dll
Syntax
public abstract class WebSocketBehavior : IWebSocketSession
Constructors
|
Improve this Doc
View Source
WebSocketBehavior()
Declaration
protected WebSocketBehavior()
Properties
|
Improve this Doc
View Source
Context
Gets the information in a handshake request to the WebSocket service.
Declaration
public WebSocketContext Context { get; }
Property Value
Type |
Description |
WebSocketContext |
A WebSocketContext instance that provides the access to the handshake request,
or null if the WebSocket connection isn't established.
|
|
Improve this Doc
View Source
EmitOnPing
Gets or sets a value indicating whether the
WebSocket used in a session emits
a
OnMessage event when receives a Ping.
Declaration
public bool EmitOnPing { get; set; }
Property Value
Type |
Description |
System.Boolean |
true if the WebSocket emits a OnMessage event
when receives a Ping; otherwise, false . The default value is false .
|
|
Improve this Doc
View Source
ID
Gets the unique ID of a session.
Declaration
public string ID { get; }
Property Value
Type |
Description |
System.String |
A System.String that represents the unique ID of the session,
or null if the WebSocket connection isn't established.
|
|
Improve this Doc
View Source
IgnoreExtensions
Gets or sets a value indicating whether the WebSocket service ignores
the Sec-WebSocket-Extensions header included in a handshake request.
Declaration
public bool IgnoreExtensions { get; set; }
Property Value
Type |
Description |
System.Boolean |
true if the WebSocket service ignores the extensions requested from
a client; otherwise, false . The default value is false .
|
|
Improve this Doc
View Source
OriginValidator
Gets or sets the delegate called to validate the Origin header included in
a handshake request to the WebSocket service.
Declaration
public Func<string, bool> OriginValidator { get; set; }
Property Value
Type |
Description |
System.Func<System.String, System.Boolean> |
A Func<string, bool> delegate that references the method(s) used to
validate the origin header.
System.String parameter passed to this delegate represents the value of
the origin header to validate if any.
This delegate should return true if the origin header is valid.
The default value is null, and it does nothing to validate.
|
|
Improve this Doc
View Source
Protocol
Gets or sets the WebSocket subprotocol used in the WebSocket service.
Declaration
public string Protocol { get; set; }
Property Value
Type |
Description |
System.String |
A System.String that represents the subprotocol if any.
The default value is System.String.Empty.
The value to set must be a token defined in
RFC 2616.
|
|
Improve this Doc
View Source
Sessions
Gets the access to the sessions in the WebSocket service.
Declaration
protected WebSocketSessionManager Sessions { get; }
Property Value
|
Improve this Doc
View Source
StartTime
Gets the time that a session has started.
Declaration
public DateTime StartTime { get; }
Property Value
Type |
Description |
System.DateTime |
A System.DateTime that represents the time that the session has started,
or System.DateTime.MaxValue if the WebSocket connection isn't established.
|
|
Improve this Doc
View Source
State
Gets the state of the
WebSocket used in a session.
Declaration
public WebSocketState State { get; }
Property Value
Methods
|
Improve this Doc
View Source
Error(String, Exception)
Declaration
protected void Error(string message, Exception exception)
Parameters
Type |
Name |
Description |
System.String |
message |
A System.String that represents the error message.
|
System.Exception |
exception |
An System.Exception instance that represents the cause of the error if any.
|
|
Improve this Doc
View Source
OnClose(CloseEventArgs)
Called when the WebSocket connection used in a session has been closed.
Declaration
protected virtual void OnClose(CloseEventArgs e)
Parameters
|
Improve this Doc
View Source
OnError(ErrorEventArgs)
Called when the
WebSocket used in a session gets an error.
Declaration
protected virtual void OnError(ErrorEventArgs e)
Parameters
|
Improve this Doc
View Source
OnMessage(MessageEventArgs)
Called when the
WebSocket used in a session receives a message.
Declaration
protected virtual void OnMessage(MessageEventArgs e)
Parameters
|
Improve this Doc
View Source
OnOpen()
Called when the WebSocket connection used in a session has been established.
Declaration
protected virtual void OnOpen()
|
Improve this Doc
View Source
Send(Byte[])
Sends binary data
to the client on a session.
Declaration
protected void Send(byte[] data)
Parameters
Type |
Name |
Description |
System.Byte[] |
data |
An array of System.Byte that represents the binary data to send.
|
|
Improve this Doc
View Source
Send(FileInfo)
Sends the specified file
as binary data to the client on a session.
Declaration
protected void Send(FileInfo file)
Parameters
Type |
Name |
Description |
System.IO.FileInfo |
file |
A System.IO.FileInfo that represents the file to send.
|
|
Improve this Doc
View Source
Send(String)
Sends text data
to the client on a session.
Declaration
protected void Send(string data)
Parameters
Type |
Name |
Description |
System.String |
data |
A System.String that represents the text data to send.
|
|
Improve this Doc
View Source
SendAsync(Byte[], Action<Boolean>)
Sends binary data
asynchronously to the client on a session.
Declaration
protected void SendAsync(byte[] data, Action<bool> completed)
Parameters
Type |
Name |
Description |
System.Byte[] |
data |
An array of System.Byte that represents the binary data to send.
|
System.Action<System.Boolean> |
completed |
An Action<bool> delegate that references the method(s) called when
the send is complete. A System.Boolean passed to this delegate is true
if the send is complete successfully.
|
|
Improve this Doc
View Source
SendAsync(FileInfo, Action<Boolean>)
Sends the specified file
as binary data asynchronously to
the client on a session.
Declaration
protected void SendAsync(FileInfo file, Action<bool> completed)
Parameters
Type |
Name |
Description |
System.IO.FileInfo |
file |
A System.IO.FileInfo that represents the file to send.
|
System.Action<System.Boolean> |
completed |
An Action<bool> delegate that references the method(s) called when
the send is complete. A System.Boolean passed to this delegate is true
if the send is complete successfully.
|
|
Improve this Doc
View Source
SendAsync(Stream, Int32, Action<Boolean>)
Sends binary data from the specified System.IO.Stream asynchronously to
the client on a session.
Declaration
protected void SendAsync(Stream stream, int length, Action<bool> completed)
Parameters
Type |
Name |
Description |
System.IO.Stream |
stream |
A System.IO.Stream from which contains the binary data to send.
|
System.Int32 |
length |
An System.Int32 that represents the number of bytes to send.
|
System.Action<System.Boolean> |
completed |
An Action<bool> delegate that references the method(s) called when
the send is complete. A System.Boolean passed to this delegate is true
if the send is complete successfully.
|
|
Improve this Doc
View Source
SendAsync(String, Action<Boolean>)
Sends text data
asynchronously to the client on a session.
Declaration
protected void SendAsync(string data, Action<bool> completed)
Parameters
Type |
Name |
Description |
System.String |
data |
A System.String that represents the text data to send.
|
System.Action<System.Boolean> |
completed |
An Action<bool> delegate that references the method(s) called when
the send is complete. A System.Boolean passed to this delegate is true
if the send is complete successfully.
|
Implements
Extension Methods