Exemplo n.º 1
0
        /// <summary>
        /// Return WebSocket connection state.
        /// </summary>
        /// <returns>The state.</returns>
        public WebSocketState GetState()
        {
            int state = WebSocketGetState(this.instanceId);

            if (state < 0)
            {
                throw WebSocketHelpers.GetErrorMessageFromCode(state, null);
            }

            switch (state)
            {
            case 0:
                return(WebSocketState.Connecting);

            case 1:
                return(WebSocketState.Open);

            case 2:
                return(WebSocketState.Closing);

            case 3:
                return(WebSocketState.Closed);

            default:
                return(WebSocketState.Closed);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Close WebSocket connection with optional status code and reason.
        /// </summary>
        /// <param name="code">Close status code.</param>
        /// <param name="reason">Reason string.</param>
        public void Close(WebSocketCloseCode code = WebSocketCloseCode.Normal, string reason = null)
        {
            int ret = WebSocketClose(this.instanceId, (int)code, reason);

            if (ret < 0)
            {
                throw WebSocketHelpers.GetErrorMessageFromCode(ret, null);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Send binary data over the socket.
        /// </summary>
        /// <param name="data">Payload data.</param>
        public void Send(byte[] data)
        {
            int ret = WebSocketSend(this.instanceId, data, data.Length);

            if (ret < 0)
            {
                throw WebSocketHelpers.GetErrorMessageFromCode(ret, null);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Open WebSocket connection
        /// </summary>
        public void Connect()
        {
            int ret = WebSocketConnect(this.instanceId);

            if (ret < 0)
            {
                throw WebSocketHelpers.GetErrorMessageFromCode(ret, null);
            }
        }