Пример #1
0
        /// <summary>
        /// Verify that the server's response is correct.
        /// </summary>
        /// <param name="aHeaders">Header with the response data.</param>
        public void VerifyS2CResponse(WebSocketHeaders aHeaders)
        {
            if (mLog.IsDebugEnabled)
            {
                mLog.Debug(WebSocketMessage.VERIFYING_S2C_RESPONSE);
            }

            if (!aHeaders.GetFirstLineResponse.Equals(WebSocketMessage.HTTP_SWITCHING_PROTOCOL))
            {
                throw new WebSocketException(WebSocketMessage.CONNECTION_FAILED_HTTP);
            }
            if (!aHeaders.GetResponseField(WebSocketConstants.UPGRADE).Equals(WebSocketMessage.WEBSOCKET1))
            {
                throw new WebSocketException(WebSocketMessage.CONNECTION_FAILED_UPGRADE);
            }
            if (!aHeaders.GetResponseField(WebSocketConstants.CONNECTION).Equals(WebSocketMessage.UPGRADE) &&
                !aHeaders.GetResponseField(WebSocketConstants.CONNECTION).Equals(WebSocketMessage.LOWUPGRADE))
            {
                throw new WebSocketException(WebSocketMessage.CONNECTION_FAILED_CONNECTION);
            }
            if (!aHeaders.GetResponseField(WebSocketConstants.SEC_WEBSOCKET_ACCEPT).Equals(mHybiKeyAccept))
            {
                throw new WebSocketException(WebSocketMessage.CONNECTION_FAILED_SEC_WEBSOCKET_KEY);
            }
            if (!aHeaders.GetResponseField(WebSocketConstants.SEC_WEBSOCKET_PROTOCOL).Equals(mProtocol))
            {
                throw new WebSocketException(WebSocketMessage.CONNECTION_FAILED_SEC_WEBSOCKET_PROTOCOL);
            }
        }
Пример #2
0
        /// <summary>
        /// Calls the with timeout.
        /// </summary>
        /// <param name="aAction">Action.</param>
        /// <param name="aTimeoutMilliseconds">Timeout milliseconds.</param>
        /// <param name="lHeaders"> WebSocket Headers.</param>
        public static void CallWithTimeout(Action<WebSocketHeaders> aAction, int aTimeoutMilliseconds, WebSocketHeaders lHeaders)
        {
            Thread lThreadToKill = null;
            Action lWrappedAction = () =>
            {
                lThreadToKill = Thread.CurrentThread;
                aAction(lHeaders);
            };

            IAsyncResult lResult = lWrappedAction.BeginInvoke(null, null);
            if (lResult.AsyncWaitHandle.WaitOne(aTimeoutMilliseconds))
            {
                lWrappedAction.EndInvoke(lResult);
            }
            else
            {
                lThreadToKill.Abort();
                throw new TimeoutException(WebSocketMessage.TIMEOUT);
            }
        }
Пример #3
0
 protected override void OnOpenConnection(WebSocketHeaders aHeaders)
 {
     if (open != null)
         open(this, aHeaders);
 }
Пример #4
0
        /// <summary>
        /// Calls the with timeout.
        /// </summary>
        /// <param name="aAction">Action.</param>
        /// <param name="aTimeoutMilliseconds">Timeout milliseconds.</param>
        /// <param name="lHeaders"> WebSocket Headers.</param>
        public static void CallWithTimeout(Action <WebSocketHeaders> aAction, int aTimeoutMilliseconds, WebSocketHeaders lHeaders)
        {
            Thread lThreadToKill  = null;
            Action lWrappedAction = () =>
            {
                lThreadToKill = Thread.CurrentThread;
                aAction(lHeaders);
            };

            IAsyncResult lResult = lWrappedAction.BeginInvoke(null, null);

            if (lResult.AsyncWaitHandle.WaitOne(aTimeoutMilliseconds))
            {
                lWrappedAction.EndInvoke(lResult);
            }
            else
            {
                lThreadToKill.Abort();
                throw new TimeoutException(WebSocketMessage.TIMEOUT);
            }
        }
Пример #5
0
 protected virtual void OnOpenConnection(WebSocketHeaders aHeaders)
 {
     if (open != null)
         open(this, aHeaders);
 }
Пример #6
0
 private void Open(WebSocketTokenClient sender, WebSocketHeaders e)
 {
     gb_send.Enabled = true;
     button3.Enabled = false;
     tb_URL.Enabled = false;
     button4.Enabled = true;
     listBox1.Items.Add("Connection opened");
     listBox1.Items.Add("JWSSESSIONID = " + e.GetCookies[0].Split('=')[1].Split(';')[0]);
 }