• MARS Website
  • Core API
  • SmartOpenHamburg API
  • Model Components API
  • Common API
Show / Hide Table of Contents
  • Mars.Common
    • GeoHash
    • GeoHashDecoder
    • GeohashDecodeResult
    • GeoHashEncoder
    • GeoHashPrecision
    • Hyperrectangle
    • InputHashHelper
    • PositionHelper
  • Mars.Common.Collections
    • BinaryArrayHeap<T>
    • DoubleBits
    • FibonacciHeap<T, TKey>
    • FibonacciHeapDoubleKey<T>
    • FibonacciHeapNode<T, TKey>
    • FibonacciHeapNodeDoubleKey<T>
    • HeapNode
    • IntervalSize
    • K2DTree<T>
    • K2dTreeNode<T>
    • KdTree
    • KdTree<T>
    • KdTreeBase<TNode>
    • KdTreeNode
    • KdTreeNode<T>
    • KdTreeNodeBase<TNode>
    • KdTreeNodeCollection<TNode>
    • KdTreeNodeList<T>
    • Key
    • Node<T>
    • NodeBase<T>
    • NodeDataContainer<T>
    • NodeDistance<TNode>
    • QuadTree<T>
    • Root<T>
    • TreeDataContainer<T>
  • Mars.Common.Collections.CritBit
    • ICritBitTree<TValue>
  • Mars.Common.Collections.Graph
    • EdgeData
    • GraphData
    • GraphSerializer
    • ISpatialGraph
    • KeyContainer
    • NodeData
    • SpatialGraph
    • SpatialGraphHelper
  • Mars.Common.Collections.Graph.Algorithms
    • AStar
    • CompressedPathDatabase
    • ContractionSearch
    • DepthLimitedTraversal
  • Mars.Common.Collections.Graph.Helper
    • INodeFinder
    • KdTreeNodeFinder
    • RunLengthEncoder
  • Mars.Common.Collections.KNNGraph
    • DefaultRandomGenerator
    • DistanceUtils
    • EventSources
    • EventSources.GraphBuildEventSource
    • EventSources.GraphSearchEventSource
    • IProgressReporter
    • IProvideRandomValues
    • KnnGraph<TItem, TDistance>
    • KnnGraph<TItem, TDistance>.KnnSearchResult
    • KnnGraph<TItem, TDistance>.Parameters
    • Node
    • ReverseComparer<T>
    • ReverseComparerExtensions
    • SelectionKind
    • TravelingCosts<TItem, TDistance>
  • Mars.Common.Compat
    • FormatDecoderAttribute
    • FormatEncoderAttribute
    • FormatHandlerAttribute
    • IntegerAttribute
    • NegativeIntegerAttribute
    • NonnegativeIntegerAttribute
    • NonpositiveIntegerAttribute
    • PositiveIntegerAttribute
  • Mars.Common.Data
    • DomainDataImporter
  • Mars.Common.Data.Providers
    • AscDataProvider
    • GeoJsonFeatureCollectionConverter
    • GeoJsonFeatureConverter
    • GeoJsonHelper
    • GeometryDataProvider
    • GraphMlProvider
    • HttpDataProvider
    • IDataProvider<TInput>
    • JsonFileDataProvider
    • JsonTextDataProvider
    • XmlFileDataProvider
    • XmlTextDataProvider
  • Mars.Common.Exceptions
    • DimensionMismatchException
    • ParseException
  • Mars.Common.IO
    • ExtensionMethods
    • FileClientUtils
    • FileKeys
    • HttpClientUtils
    • ObjectSerialize
    • Serializer
    • SerializerCompression
    • SparseFormat
    • SparseReader
    • SparseWriter
  • Mars.Common.IO.Attributes
    • SerializationBinderAttribute
    • SurrogateSelectorAttribute
  • Mars.Common.IO.Console
    • ChildProgressBar
    • IProgressBar
    • ProgressBar
    • ProgressBarBase
    • ProgressBarHeight
    • ProgressBarOptions
    • ProgressBarSimple
  • Mars.Common.IO.Csv
    • CsvAnalyzer
    • CsvReader
    • CsvReader.RecordEnumerator
    • CsvWriter
    • MissingFieldAction
    • ParseErrorAction
    • ValueTrimmingOptions
  • Mars.Common.IO.Events
    • ParseErrorEventArgs
  • Mars.Common.IO.Exceptions
    • MalformedCsvException
    • MissingFieldCsvException
  • Mars.Common.IO.Mapped
    • Context
    • DefaultArrayFactory
    • Extensions
    • IArrayFactory
    • ISerializableToStream
    • MappedAccessor<T>
    • MemoryMap
    • MemoryMap.CreateAccessorFunc<T>
    • MemoryMap.ReadFromDelegate<T>
    • MemoryMap.WriteToDelegate<T>
    • MemoryMapDelegates
    • MemoryMapDelegates.CreateAccessorFunc<T>
    • MemoryMapStream
  • Mars.Common.IO.Mapped.Accessors
    • MappedAccessorByte
    • MappedAccessorDouble
    • MappedAccessorInt16
    • MappedAccessorInt32
    • MappedAccessorInt64
    • MappedAccessorSingle
    • MappedAccessorUInt16
    • MappedAccessorUInt32
    • MappedAccessorUInt64
    • MappedAccessorVariable<T>
  • Mars.Common.IO.Mapped.Arrays
    • Array<T>
    • ArrayBase<T>
    • ArrayProfile
    • MappedArray<TMapped, T>
    • MappedArray<TMapped, T>.MapFrom
    • MappedArray<TMapped, T>.MapTo
    • MemoryArray<T>
    • VariableArray<T>
  • Mars.Common.IO.Mapped.Collections
    • MemoryBackedDictionary<TKey, TValue>
    • MemoryBackedList<T>
  • Mars.Common.IO.Mapped.Indexes
    • Index<T>
  • Mars.Common.IO.Mapped.Streams
    • CappedStream
  • Mars.Common.Socket
    • ByteOrder
    • CloseEventArgs
    • CloseStatusCode
    • CompressionMethod
    • ErrorEventArgs
    • Ext
    • MessageEventArgs
    • WebSocket
    • WebSocketException
    • WebSocketState
  • Mars.Common.Socket.Server
    • IWebSocketSession
    • WebHeaderCollection
    • WebSocketBehavior
    • WebSocketContext
    • WebSocketServer
    • WebSocketServiceHost
    • WebSocketServiceManager
    • WebSocketSessionManager
  • Mars.Numerics
    • Classes
    • Combinatorics
    • Constants
    • Distance
    • Elementwise
    • Jagged
    • MathematicsException
    • MathHelper
    • Matrix
    • MatrixOrder
    • MatrixType
    • Norm
    • Sort
    • Sorting
    • Sparse
    • Sparse<T>
    • Tools
    • Vector
    • VectorHelper
    • VectorType
  • Mars.Numerics.Comparers
    • ArrayComparer<T>
    • ComparerDirection
    • CustomComparer<T>
    • ElementComparer
    • ElementComparer<T>
    • GeneralComparer
    • StableComparer<T>
  • Mars.Numerics.Distances
    • Angular
    • Chebyshev
    • Cosine
    • Dirac<T>
    • Euclidean
    • Hamming
    • Hamming<T>
    • Haversine
    • Jaccard
    • Jaccard<T>
    • Kulczynski
    • Levenshtein
    • Levenshtein<T>
    • Manhattan
    • Matching
    • Minkowski
    • SquareEuclidean
    • Vincenty
    • Vincenty.Ellipsoid
  • Mars.Numerics.Distances.Base
    • IDistance<T>
    • IDistance<TFirst, TSecond>
    • IMetric<T>
    • ISimilarity<T, TU>
    • ISimilarity<T>
  • Mars.Numerics.Exceptions
    • DimensionMismatchException
    • NonPositiveDefiniteMatrixException
    • SingularMatrixException
  • Mars.Numerics.Formats
    • DefaultMatrixFormatProvider
    • IMatrixFormatProvider
    • MatrixFormatProviderBase
    • MatrixFormatter
    • OctaveMatrixFormatProvider
  • Mars.Numerics.Ranges
    • ByteRange
    • DoubleRange
    • FloatRange
    • IntRange
    • IRange<T>
  • Mars.Numerics.Statistics
    • ConstValueDistribution<T>
    • Distribution<T>
    • FastGaussianDistributionD
    • FastGaussianDistributionF
    • IDistribution
    • UniformDiscreteDistribution
    • UniformDistributionD
    • UniformDistributionF
  • Mars.Numerics.Statistics.Base
    • BinarySearch
    • DistributionBase
    • ISampleableDistribution<TObservations>
    • IUnivariateDistribution
    • IUnivariateDistribution<TObservation>
    • UnivariateDiscreteDistribution

Class WebSocketServer

Provides a WebSocket protocol server.
Inheritance
System.Object
WebSocketServer
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()
Namespace: Mars.Common.Socket.Server
Assembly: Mars.Common.dll
Syntax
public class WebSocketServer
Remarks
This class can provide multiple WebSocket services.

Constructors

| Improve this Doc View Source

WebSocketServer()

Initializes a new instance of the WebSocketServer class.
Declaration
public WebSocketServer()
Remarks
The new instance listens for incoming handshake requests on System.Net.IPAddress.Any and port 80.
| Improve this Doc View Source

WebSocketServer(Int32, Boolean)

Initializes a new instance of the WebSocketServer class with the specified port and secure.
Declaration
public WebSocketServer(int port, bool secure)
Parameters
Type Name Description
System.Int32 port An System.Int32 that represents the number of the port on which to listen.
System.Boolean secure A System.Boolean: true if the new instance provides secure connections; otherwise, false.
Remarks
The new instance listens for incoming handshake requests on System.Net.IPAddress.Any and port.
Exceptions
Type Condition
System.ArgumentOutOfRangeException port is less than 1 or greater than 65535.
| Improve this Doc View Source

WebSocketServer(Int32)

Initializes a new instance of the WebSocketServer class with the specified port.
Declaration
public WebSocketServer(int port)
Parameters
Type Name Description
System.Int32 port An System.Int32 that represents the number of the port on which to listen.
Remarks

The new instance listens for incoming handshake requests on System.Net.IPAddress.Any and port.

It provides secure connections if port is 443.

Exceptions
Type Condition
System.ArgumentOutOfRangeException port is less than 1 or greater than 65535.
| Improve this Doc View Source

WebSocketServer(IPAddress, Int32, Boolean)

Initializes a new instance of the WebSocketServer class with the specified address, port, and secure.
Declaration
public WebSocketServer(IPAddress address, int port, bool secure)
Parameters
Type Name Description
System.Net.IPAddress address A System.Net.IPAddress that represents the local IP address on which to listen.
System.Int32 port An System.Int32 that represents the number of the port on which to listen.
System.Boolean secure A System.Boolean: true if the new instance provides secure connections; otherwise, false.
Remarks
The new instance listens for incoming handshake requests on address and port.
Exceptions
Type Condition
System.ArgumentNullException address is null.
System.ArgumentException address is not a local IP address.
System.ArgumentOutOfRangeException port is less than 1 or greater than 65535.
| Improve this Doc View Source

WebSocketServer(IPAddress, Int32)

Initializes a new instance of the WebSocketServer class with the specified address and port.
Declaration
public WebSocketServer(IPAddress address, int port)
Parameters
Type Name Description
System.Net.IPAddress address A System.Net.IPAddress that represents the local IP address on which to listen.
System.Int32 port An System.Int32 that represents the number of the port on which to listen.
Remarks

The new instance listens for incoming handshake requests on address and port.

It provides secure connections if port is 443.

Exceptions
Type Condition
System.ArgumentNullException address is null.
System.ArgumentException address is not a local IP address.
System.ArgumentOutOfRangeException port is less than 1 or greater than 65535.
| Improve this Doc View Source

WebSocketServer(String)

Initializes a new instance of the WebSocketServer class with the specified url.
Declaration
public WebSocketServer(string url)
Parameters
Type Name Description
System.String url A System.String that represents the WebSocket URL of the server.
Remarks

The new instance listens for incoming handshake requests on the IP address of the host of url and the port of url.

Either port 80 or 443 is used if url includes no port. Port 443 is used if the scheme of url is wss; otherwise, port 80 is used.

The new instance provides secure connections if the scheme of url is wss.

Exceptions
Type Condition
System.ArgumentNullException url is null.
System.ArgumentException

url is an empty string.

-or-

url is invalid.

Properties

| Improve this Doc View Source

Address

Gets the IP address of the server.
Declaration
public IPAddress Address { get; }
Property Value
Type Description
System.Net.IPAddress A System.Net.IPAddress that represents the local IP address on which to listen for incoming handshake requests.
Remarks
This class can provide multiple WebSocket services.
| Improve this Doc View Source

AllowForwardedRequest

Gets or sets a value indicating whether the server accepts every handshake request without checking the request URI.
Declaration
public bool AllowForwardedRequest { get; set; }
Property Value
Type Description
System.Boolean

true if the server accepts every handshake request without checking the request URI; otherwise, false.

The default value is false.

Remarks
The set operation does nothing if the server has already started or it is shutting down.
| Improve this Doc View Source

IsListening

Gets a value indicating whether the server has started.
Declaration
public bool IsListening { get; }
Property Value
Type Description
System.Boolean true if the server has started; otherwise, false.
Remarks
This class can provide multiple WebSocket services.
| Improve this Doc View Source

KeepClean

Gets or sets a value indicating whether the server cleans up the inactive sessions periodically.
Declaration
public bool KeepClean { get; set; }
Property Value
Type Description
System.Boolean

true if the server cleans up the inactive sessions every 60 seconds; otherwise, false.

The default value is true.

Remarks
The set operation does nothing if the server has already started or it is shutting down.
| Improve this Doc View Source

Port

Gets the port of the server.
Declaration
public int Port { get; }
Property Value
Type Description
System.Int32 An System.Int32 that represents the number of the port on which to listen for incoming handshake requests.
Remarks
This class can provide multiple WebSocket services.
| Improve this Doc View Source

ReuseAddress

Gets or sets a value indicating whether the server is allowed to be bound to an address that is already in use.
Declaration
public bool ReuseAddress { get; set; }
Property Value
Type Description
System.Boolean

true if the server is allowed to be bound to an address that is already in use; otherwise, false.

The default value is false.

Remarks

You should set this property to true if you would like to resolve to wait for socket in TIME_WAIT state.

The set operation does nothing if the server has already started or it is shutting down.

| Improve this Doc View Source

WaitTime

Gets or sets the time to wait for the response to the WebSocket Ping or Close.
Declaration
public TimeSpan WaitTime { get; set; }
Property Value
Type Description
System.TimeSpan

A System.TimeSpan to wait for the response.

The default value is the same as 1 second.

Remarks
The set operation does nothing if the server has already started or it is shutting down.
Exceptions
Type Condition
System.ArgumentOutOfRangeException The value specified for a set operation is zero or less.
| Improve this Doc View Source

WebSocketServices

Gets the management function for the WebSocket services provided by the server.
Declaration
public WebSocketServiceManager WebSocketServices { get; }
Property Value
Type Description
WebSocketServiceManager A WebSocketServiceManager that manages the WebSocket services provided by the server.
Remarks
This class can provide multiple WebSocket services.

Methods

| Improve this Doc View Source

AddWebSocketService<TBehaviorWithNew>(String, Action<TBehaviorWithNew>)

Adds a WebSocket service with the specified behavior, path, and initializer.
Declaration
public void AddWebSocketService<TBehaviorWithNew>(string path, Action<TBehaviorWithNew> initializer)
    where TBehaviorWithNew : WebSocketBehavior, new()
Parameters
Type Name Description
System.String path A System.String that represents an absolute path to the service to add.
System.Action<TBehaviorWithNew> initializer

An Action<TBehaviorWithNew> delegate or null if not needed.

That delegate invokes the method called for initializing a new session instance for the service.

Type Parameters
Name Description
TBehaviorWithNew

The type of the behavior for the service.

It must inherit the WebSocketBehavior class and have a public parameterless constructor.

Remarks
path is converted to a URL-decoded string and '/' is trimmed from the end of the converted string if any.
Exceptions
Type Condition
System.ArgumentNullException path is null.
System.ArgumentException

path is an empty string.

-or-

path is not an absolute path.

-or-

path includes either or both query and fragment components.

-or-

path is already in use.

| Improve this Doc View Source

AddWebSocketService<TBehavior>(String, Func<TBehavior>)

Adds a WebSocket service with the specified behavior, path, and creator.
Declaration
[Obsolete("This method will be removed. Use added one instead.")]
public void AddWebSocketService<TBehavior>(string path, Func<TBehavior> creator)
    where TBehavior : WebSocketBehavior
Parameters
Type Name Description
System.String path A System.String that represents an absolute path to the service to add.
System.Func<TBehavior> creator

A Func<TBehavior> delegate.

It invokes the method called for creating a new session instance for the service.

The method must create a new instance of the specified behavior class and return it.

Type Parameters
Name Description
TBehavior

The type of the behavior for the service.

It must inherit the WebSocketBehavior class.

Remarks
path is converted to a URL-decoded string and '/' is trimmed from the end of the converted string if any.
Exceptions
Type Condition
System.ArgumentNullException

path is null.

-or-

creator is null.

System.ArgumentException

path is an empty string.

-or-

path is not an absolute path.

-or-

path includes either or both query and fragment components.

-or-

path is already in use.

| Improve this Doc View Source

AddWebSocketService<TBehaviorWithNew>(String)

Adds a WebSocket service with the specified behavior and path.
Declaration
public void AddWebSocketService<TBehaviorWithNew>(string path)
    where TBehaviorWithNew : WebSocketBehavior, new()
Parameters
Type Name Description
System.String path A System.String that represents an absolute path to the service to add.
Type Parameters
Name Description
TBehaviorWithNew

The type of the behavior for the service.

It must inherit the WebSocketBehavior class and have a public parameterless constructor.

Remarks
path is converted to a URL-decoded string and '/' is trimmed from the end of the converted string if any.
Exceptions
Type Condition
System.ArgumentNullException path is null.
System.ArgumentException

path is an empty string.

-or-

path is not an absolute path.

-or-

path includes either or both query and fragment components.

-or-

path is already in use.

| Improve this Doc View Source

RemoveWebSocketService(String)

Removes a WebSocket service with the specified path.
Declaration
public bool RemoveWebSocketService(string path)
Parameters
Type Name Description
System.String path A System.String that represents an absolute path to the service to remove.
Returns
Type Description
System.Boolean true if the service is successfully found and removed; otherwise, false.
Remarks

path is converted to a URL-decoded string and '/' is trimmed from the end of the converted string if any.

The service is stopped with close status 1001 (going away) if it has already started.

Exceptions
Type Condition
System.ArgumentNullException path is null.
System.ArgumentException

path is an empty string.

-or-

path is not an absolute path.

-or-

path includes either or both query and fragment components.

| Improve this Doc View Source

Start()

Starts receiving incoming handshake requests.
Declaration
public void Start()
Remarks
This method does nothing if the server has already started or it is shutting down.
Exceptions
Type Condition
System.InvalidOperationException

There is no server certificate for secure connections.

-or-

The underlying System.Net.Sockets.TcpListener has failed to start.

| Improve this Doc View Source

Stop()

Stops receiving incoming handshake requests and closes each connection.
Declaration
public void Stop()
Remarks
This method does nothing if the server is not started, it is shutting down, or it has already stopped.
Exceptions
Type Condition
System.InvalidOperationException The underlying System.Net.Sockets.TcpListener has failed to stop.
| Improve this Doc View Source

Stop(CloseStatusCode, String)

Stops receiving incoming handshake requests and closes each connection with the specified code and reason.
Declaration
public void Stop(CloseStatusCode code, string reason)
Parameters
Type Name Description
CloseStatusCode code

One of the CloseStatusCode enum values.

It represents the status code indicating the reason for the close.

System.String reason

A System.String that represents the reason for the close.

The size must be 123 bytes or less in UTF-8.

Remarks
This method does nothing if the server is not started, it is shutting down, or it has already stopped.
Exceptions
Type Condition
System.ArgumentException

code is MandatoryExtension.

-or-

code is NoStatus and there is reason.

-or-

reason could not be UTF-8-encoded.

System.ArgumentOutOfRangeException The size of reason is greater than 123 bytes.
System.InvalidOperationException The underlying System.Net.Sockets.TcpListener has failed to stop.
| Improve this Doc View Source

Stop(UInt16, String)

Stops receiving incoming handshake requests and closes each connection with the specified code and reason.
Declaration
public void Stop(ushort code, string reason)
Parameters
Type Name Description
System.UInt16 code

A System.UInt16 that represents the status code indicating the reason for the close.

The status codes are defined in Section 7.4 of RFC 6455.

System.String reason

A System.String that represents the reason for the close.

The size must be 123 bytes or less in UTF-8.

Remarks
This method does nothing if the server is not started, it is shutting down, or it has already stopped.
Exceptions
Type Condition
System.ArgumentOutOfRangeException

code is less than 1000 or greater than 4999.

-or-

The size of reason is greater than 123 bytes.

System.ArgumentException

code is 1010 (mandatory extension).

-or-

code is 1005 (no status) and there is reason.

-or-

reason could not be UTF-8-encoded.

System.InvalidOperationException The underlying System.Net.Sockets.TcpListener has failed to stop.

Extension Methods

Serializer.Save<T>(T, out Byte[], SerializerCompression)
Serializer.Save<T>(T, Stream, SerializerCompression)
Serializer.Save<T>(T, BinaryFormatter, Stream, SerializerCompression)
Serializer.Save<T>(T, String, SerializerCompression)
Serializer.Save<T>(T, String)
Matrix.Concatenate<T>(T, T[])
Matrix.Replace<T>(T, Object, Object)
DomainDataImporter.Import(Object, InputConfiguration)
ObjectSerialize.Serialize(Object)
Matrix.IsEqual(Object, Object, Decimal, Decimal)
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © MARS GROUP. HAW Hamburg