当前位置: 首页>>代码示例>>C#>>正文


C# WebSocketState类代码示例

本文整理汇总了C#中WebSocketState的典型用法代码示例。如果您正苦于以下问题:C# WebSocketState类的具体用法?C# WebSocketState怎么用?C# WebSocketState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


WebSocketState类属于命名空间,在下文中一共展示了WebSocketState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: tmrConnectionChecker_Tick

 private void tmrConnectionChecker_Tick(object sender, EventArgs e)
 {
     if (firstTime)
     {
         firstTime = false;
         try
         {
             Main.connection.connect(txtIP.Text, Int32.Parse(txtPort.Text));
         }
         catch (Exception)
         {
         }
     }
     WebSocketState st = Main.connection.state;
     if (st != lastState)
     {
         if (st == WebSocketState.Closed)
         {
             btnCnnct.Enabled = true;
             btnCnnct.Text = "Connect";
         }
         else
         {
             btnCnnct.Enabled = btnOK.Enabled = false;
             btnCnnct.Text = Enum.GetName(typeof(WebSocketState), st);
         }
         btnOK.Enabled = (st == WebSocketState.Open);
         lastState = st;
     }
 }
开发者ID:zeitoonco,项目名称:zds,代码行数:30,代码来源:login.cs

示例2: OwinWebSocketAdapter

 public OwinWebSocketAdapter(IDictionary<string, object> websocketContext, string subProtocol)
 {
     _websocketContext = websocketContext;
     _sendAsync = (WebSocketSendAsync)websocketContext[OwinConstants.WebSocket.SendAsync];
     _receiveAsync = (WebSocketReceiveAsync)websocketContext[OwinConstants.WebSocket.ReceiveAsync];
     _closeAsync = (WebSocketCloseAsync)websocketContext[OwinConstants.WebSocket.CloseAsync];
     _state = WebSocketState.Open;
     _subProtocol = subProtocol;
 }
开发者ID:EgoDust,项目名称:HttpAbstractions,代码行数:9,代码来源:OwinWebSocketAdapter.cs

示例3: Dispose

        public override void Dispose()
        {
            if (_state >= WebSocketState.Closed) // or Aborted
            {
                return;
            }

            _state = WebSocketState.Closed;
            _session.WebSocketDispose();
        }
开发者ID:tmds,项目名称:Tmds.SockJS,代码行数:10,代码来源:SessionWebSocket.cs

示例4: CloseNoopsIfInTerminalState

        public async Task CloseNoopsIfInTerminalState(WebSocketState state)
        {
            var webSocket = new Mock<WebSocket>();
            var webSocketHandler = new Mock<WebSocketHandler>(64 * 1024, new Mock<ILogger>().Object) {CallBase = true};

            webSocket.Setup(m => m.State).Returns(state);
            webSocketHandler.Object.WebSocket = webSocket.Object;

            await webSocketHandler.Object.CloseAsync();

            webSocket.Verify(m => m.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None), Times.Never());
        }
开发者ID:leloulight,项目名称:SignalR-Server,代码行数:12,代码来源:WebSocketFacts.cs

示例5: CommonWebSocket

 public CommonWebSocket(Stream stream, string subProtocol, TimeSpan keepAliveInterval, int receiveBufferSize, bool maskOutput, bool useZeroMask, bool unmaskInput)
 {
     _stream = stream;
     _subProtocl = subProtocol;
     _state = WebSocketState.Open;
     _receiveBuffer = new byte[receiveBufferSize];
     _maskOutput = maskOutput;
     _useZeroMask = useZeroMask;
     _unmaskInput = unmaskInput;
     _writeLock = new SemaphoreSlim(1);
     if (keepAliveInterval != Timeout.InfiniteTimeSpan)
     {
         _keepAliveTimer = new Timer(SendKeepAlive, this, keepAliveInterval, keepAliveInterval);
     }
 }
开发者ID:leloulight,项目名称:WebSockets,代码行数:15,代码来源:CommonWebSocket.cs

示例6: StreamWebSocket

		public StreamWebSocket (Stream rstream, Stream wstream, Socket socket, string subProtocol, bool maskSend, ArraySegment<byte> preloaded)
		{
			this.rstream = rstream;
			this.wstream = wstream;
			// Necessary when both of rstream and wstream doesn't close socket.
			this.socket = socket;
			this.subProtocol = subProtocol;
			this.maskSend = maskSend;
			if (maskSend) {
				random = new Random ();
			}
			this.preloaded = preloaded;
			state = WebSocketState.Open;
			headerBuffer = new byte[HeaderMaxLength];
		}
开发者ID:Rubenovich,项目名称:mono,代码行数:15,代码来源:StreamWebSocket.cs

示例7: CommonWebSocket

        protected CommonWebSocket(string subProtocol, TimeSpan keepAliveInterval, int receiveBufferSize, bool maskOutput, bool useZeroMask, bool unmaskInput)
        {
            _connection = new TcpClient
            {
                NoDelay = true
            };
            _state = WebSocketState.None;

            _subProtocol = subProtocol;
            _keepAliveInterval = keepAliveInterval;
            _receiveBuffer = new byte[receiveBufferSize];
            _maskOutput = maskOutput;
            _useZeroMask = useZeroMask;
            _unmaskInput = unmaskInput;
            _writeLock = new SemaphoreSlim(1);
        }
开发者ID:AdaptiveConsulting,项目名称:ReactiveTraderCloud,代码行数:16,代码来源:CommonWebSocket.cs

示例8: CloseOutputAsync

        public async override Task CloseOutputAsync(WebSocketCloseStatus closeStatus, string statusDescription, CancellationToken cancellationToken)
        {
            ThrowIfDisposed();
            ThrowIfOutputClosed();

            var message = new Message(closeStatus, statusDescription);
            await _sendBuffer.SendAsync(message, cancellationToken);

            if (State == WebSocketState.Open)
            {
                _state = WebSocketState.CloseSent;
            }
            else if (State == WebSocketState.CloseReceived)
            {
                _state = WebSocketState.Closed;
                Close();
            }
        }
开发者ID:leloulight,项目名称:Hosting,代码行数:18,代码来源:TestWebSocket.cs

示例9: ThrowOnInvalidState

        protected static void ThrowOnInvalidState(WebSocketState state, params WebSocketState[] validStates)
        {
            string validStatesText = string.Empty;

            if (validStates != null && validStates.Length > 0)
            {
                foreach (WebSocketState currentState in validStates)
                {
                    if (state == currentState)
                    {
                        return;
                    }
                }

                validStatesText = string.Join(", ", validStates);
            }

            throw new WebSocketException(SR.Format(SR.net_WebSockets_InvalidState, state, validStatesText));
        }
开发者ID:Corillian,项目名称:corefx,代码行数:19,代码来源:WebSocket.cs

示例10: Cleanup

		public void Cleanup()
		{
			ResponseHeaders.Clear();
			Stream = null;
			_state = WebSocketState.Closed;
		}
开发者ID:bragin,项目名称:websockets,代码行数:6,代码来源:WebSocket.cs

示例11: Open

		public void Open( string url )
		{
			if (IsOpen)
			{
				Close();
				Helper.Log("FIXME: Wait for the connection to close");
			}

			_url = url;

			try
			{
				_state = WebSocketState.Connecting;
				makeHandshake( url );
			}
			catch (Exception err)
			{
				Helper.Log( "ERROR: " + err );
				_state = WebSocketState.Closed;
				throw;
			}
		}
开发者ID:bragin,项目名称:websockets,代码行数:22,代码来源:WebSocket.cs

示例12: ProcessFrame

        /// <summary>
        /// Processes a websocket frame and triggers consumer events
        /// </summary>
        /// <param name="psocketState">We need to modify the websocket state here depending on the frame</param>
        private void ProcessFrame(WebSocketState psocketState)
        {
            if (psocketState.Header.IsMasked)
            {
                byte[] unmask = psocketState.ReceivedBytes.ToArray();
                WebSocketReader.Mask(psocketState.Header.Mask, unmask);
                psocketState.ReceivedBytes = new List<byte>(unmask);
            }
            if (psocketState.Header.Opcode != WebSocketReader.OpCode.Continue  && _initialMsgTimeout > 0)
            {
                _receiveDone.Set();
                _initialMsgTimeout = 0;
            }
            switch (psocketState.Header.Opcode)
            {
                case WebSocketReader.OpCode.Ping:
                    PingDelegate pingD = OnPing;
                    if (pingD != null)
                    {
                        pingD(this, new PingEventArgs());
                    }

                    WebSocketFrame pongFrame = new WebSocketFrame(){Header = WebsocketFrameHeader.HeaderDefault(),WebSocketPayload = new byte[0]};
                    pongFrame.Header.Opcode = WebSocketReader.OpCode.Pong;
                    pongFrame.Header.IsEnd = true;
                    SendSocket(pongFrame.ToBytes());
                    break;
                case WebSocketReader.OpCode.Pong:
                 
                    PongDelegate pongD = OnPong;
                    if (pongD != null)
                    {
                        pongD(this, new PongEventArgs(){PingResponseMS = Util.EnvironmentTickCountSubtract(Util.EnvironmentTickCount(),_pingtime)});
                    }
                    break;
                case WebSocketReader.OpCode.Binary:
                    if (!psocketState.Header.IsEnd) // Not done, so we need to store this and wait for the end frame.
                    {
                        psocketState.ContinuationFrame = new WebSocketFrame
                                                             {
                                                                 Header = psocketState.Header,
                                                                 WebSocketPayload =
                                                                     psocketState.ReceivedBytes.ToArray()
                                                             };
                    }
                    else
                    {
                        // Send Done Event!
                        DataDelegate dataD = OnData;
                        if (dataD != null)
                        {
                            dataD(this,new WebsocketDataEventArgs(){Data = psocketState.ReceivedBytes.ToArray()});
                        }
                    }
                    break;
                case WebSocketReader.OpCode.Text:
                    if (!psocketState.Header.IsEnd) // Not done, so we need to store this and wait for the end frame.
                    {
                        psocketState.ContinuationFrame = new WebSocketFrame
                                                             {
                                                                 Header = psocketState.Header,
                                                                 WebSocketPayload =
                                                                     psocketState.ReceivedBytes.ToArray()
                                                             };
                    }
                    else
                    {
                        TextDelegate textD = OnText;
                        if (textD != null)
                        {
                            textD(this, new WebsocketTextEventArgs() { Data = Encoding.UTF8.GetString(psocketState.ReceivedBytes.ToArray()) });
                        }
                        
                        // Send Done Event!
                    }
                    break;
                case WebSocketReader.OpCode.Continue:  // Continuation.  Multiple frames worth of data for one message.   Only valid when not using Control Opcodes
                    //Console.WriteLine("currhead " + psocketState.Header.IsEnd);
                    //Console.WriteLine("Continuation! " + psocketState.ContinuationFrame.Header.IsEnd);
                    byte[] combineddata = new byte[psocketState.ReceivedBytes.Count+psocketState.ContinuationFrame.WebSocketPayload.Length];
                    byte[] newdata = psocketState.ReceivedBytes.ToArray();
                    Buffer.BlockCopy(psocketState.ContinuationFrame.WebSocketPayload, 0, combineddata, 0, psocketState.ContinuationFrame.WebSocketPayload.Length);
                    Buffer.BlockCopy(newdata, 0, combineddata,
                                        psocketState.ContinuationFrame.WebSocketPayload.Length, newdata.Length);
                    psocketState.ContinuationFrame.WebSocketPayload = combineddata;
                    psocketState.Header.PayloadLen = (ulong)combineddata.Length;
                    if (psocketState.Header.IsEnd)
                    {
                        if (psocketState.ContinuationFrame.Header.Opcode == WebSocketReader.OpCode.Text)
                        {
                            // Send Done event    
                            TextDelegate textD = OnText;
                            if (textD != null)
                            {
                                textD(this, new WebsocketTextEventArgs() { Data = Encoding.UTF8.GetString(combineddata) });
                            }
//.........这里部分代码省略.........
开发者ID:CassieEllen,项目名称:opensim,代码行数:101,代码来源:WebsocketServerHandler.cs

示例13: UpdateState

 public void UpdateState(WebSocketState value)
 {
     if ((_state != WebSocketState.Closed) && (_state != WebSocketState.Aborted))
     {
         _state = value;
     }
 }
开发者ID:defilerc,项目名称:corefx,代码行数:7,代码来源:WinHttpWebSocketState.cs

示例14: InterlockedCheckAndUpdateState

 public void InterlockedCheckAndUpdateState(
     WebSocketState newState,
     params WebSocketState[] validStates)
 {
     lock (_lock)
     {
         CheckValidState(validStates);
         UpdateState(newState);
     }
 }
开发者ID:defilerc,项目名称:corefx,代码行数:10,代码来源:WinHttpWebSocketState.cs

示例15: Close

        // As server
        internal void Close(HttpStatusCode code)
        {
            _readyState = WebSocketState.CLOSING;

              send (createHandshakeResponse (code));
              closeServerResources ();

              _readyState = WebSocketState.CLOSED;
        }
开发者ID:kevleyski,项目名称:websocket-sharp,代码行数:10,代码来源:WebSocket.cs


注:本文中的WebSocketState类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。