コード例 #1
0
 public void VerifyS2CResponse(WebSocketHeaders aHeaders)
 {
     if (!aHeaders.GetFirstLineResponse.Equals("HTTP/1.1 101 Switching Protocols"))
     {
         throw new WebSocketException("connection failed: missing header field in server handshake: HTTP/1.1");
     }
     if (!aHeaders.GetResponseField(WebSocketConstants.UPGRADE).Equals("websocket"))
     {
         throw new WebSocketException("connection failed: missing header field in server handshake: Upgrade");
     }
     if (!aHeaders.GetResponseField(WebSocketConstants.CONNECTION).Equals("Upgrade"))
     {
         throw new WebSocketException("connection failed: missing header field in server handshake: Connection");
     }
     if (!aHeaders.GetResponseField(WebSocketConstants.SEC_WEBSOCKET_ACCEPT).Equals(mHybiKeyAccept))
     {
         throw new WebSocketException("connection failed: missing header field in server handshake: Sec-WebSocket-Key");
     }
     if (!aHeaders.GetResponseField(WebSocketConstants.SEC_WEBSOCKET_PROTOCOL).Equals(mProtocol))
     {
         throw new WebSocketException("connection failed: missing header field in server handshake: Sec-WebSocket-Protocol");
     }
 }
コード例 #2
0
ファイル: WebSocketTimeout.cs プロジェクト: KosBeg/jwebsocket
        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("Timeout");
            }
        }
コード例 #3
0
        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("Timeout");
            }
        }