• Documentation
  • 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
      • 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
    Namespace: Mars.Common.Socket.Server
    Assembly: Mars.Common.dll
    Syntax
    public class WebSocketServer : object
    Remarks
    This class can provide multiple WebSocket services.

    Constructors

    WebSocketServer()

    Initializes a new instance of the WebSocketServer class.
    Declaration
    public WebSocketServer()
    Remarks
    The new instance listens for incoming handshake requests on and port 80.

    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
    IPAddress address A that represents the local IP address on which to listen.
    System.Int32 port An 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.

    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
    IPAddress address A that represents the local IP address on which to listen.
    System.Int32 port An that represents the number of the port on which to listen.
    System.Boolean secure A : true if the new instance provides secure connections; otherwise, false.
    Remarks
    The new instance listens for incoming handshake requests on address and port.

    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 that represents the number of the port on which to listen.
    Remarks

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

    It provides secure connections if port is 443.

    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 that represents the number of the port on which to listen.
    System.Boolean secure A : true if the new instance provides secure connections; otherwise, false.
    Remarks
    The new instance listens for incoming handshake requests on and port.

    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 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.

    Properties

    Address

    Gets the IP address of the server.
    Declaration
    public IPAddress Address { get; }
    Property Value
    Type Description
    IPAddress A that represents the local IP address on which to listen for incoming handshake requests.

    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.

    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.

    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.

    Port

    Gets the port of the server.
    Declaration
    public int Port { get; }
    Property Value
    Type Description
    System.Int32 An that represents the number of the port on which to listen for incoming handshake requests.

    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.

    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
    TimeSpan

    A 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.

    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.

    Methods

    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 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.

    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 that represents an absolute path to the service to add.
    Action<TBehaviorWithNew> initializer

    An Action<TBehaviorWithNew> delegate or langword_csharp_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.

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

    Adds a WebSocket service with the specified behavior, path, and creator.
    Declaration
    public void AddWebSocketService<TBehavior>(string path, Func<TBehavior> creator)
        where TBehavior : WebSocketBehavior
    Parameters
    Type Name Description
    System.String path A that represents an absolute path to the service to add.
    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.

    RemoveWebSocketService(String)

    Removes a WebSocket service with the specified path.
    Declaration
    public bool RemoveWebSocketService(string path)
    Parameters
    Type Name Description
    System.String path A 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.

    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.

    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.

    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 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.

    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 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 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.

    Extension Methods

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