• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# WebSocketState类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: open

        private void open()
        {
            _readyState = WebSocketState.OPEN;

              OnOpen.Emit (this, EventArgs.Empty);
              startReceiving ();
        }
开发者ID:kevleyski,项目名称:websocket-sharp,代码行数:7,代码来源:WebSocket.cs


示例17: WebSocket

 private WebSocket()
 {
     _compression = CompressionMethod.NONE;
       _cookies = new CookieCollection ();
       _extensions = String.Empty;
       _forClose = new object ();
       _forSend = new object ();
       _origin = String.Empty;
       _preAuth = false;
       _protocol = String.Empty;
       _readyState = WebSocketState.CONNECTING;
 }
开发者ID:kevleyski,项目名称:websocket-sharp,代码行数:12,代码来源:WebSocket.cs


示例18: Close

    // As server
    internal void Close (CloseEventArgs e, byte[] frameAsBytes, TimeSpan timeout)
    {
      lock (_forConn) {
        if (_readyState == WebSocketState.Closing) {
          _logger.Info ("The closing is already in progress.");
          return;
        }

        if (_readyState == WebSocketState.Closed) {
          _logger.Info ("The connection has been closed.");
          return;
        }

        _readyState = WebSocketState.Closing;
      }

      e.WasClean = closeHandshake (frameAsBytes, timeout, releaseServerResources);

      _readyState = WebSocketState.Closed;
      try {
        OnClose.Emit (this, e);
      }
      catch (Exception ex) {
        _logger.Fatal (ex.ToString ());
      }
    }
开发者ID:greeduomacro,项目名称:uomap-client,代码行数:27,代码来源:WebSocket.cs


示例19: InterlockedCheckValidStates

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


示例20: InternalAccept

 // As server
 internal void InternalAccept ()
 {
   try {
     if (acceptHandshake ()) {
       _readyState = WebSocketState.Open;
       open ();
     }
   }
   catch (Exception ex) {
     processException (ex, "An exception has occurred while accepting.");
   }
 }
开发者ID:greeduomacro,项目名称:uomap-client,代码行数:13,代码来源:WebSocket.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# WebSocketVersion类代码示例发布时间:2022-05-24
下一篇:
C# WebSocketSession类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap