CloseAsync() 공개 메소드

Closes the WebSocket connection asynchronously, and releases all associated resources.

This method does nothing if the current state of the connection is Closing or Closed.

This method does not wait for the close to be complete.

public CloseAsync ( ) : void
리턴 void
예제 #1
0
    void Start() {
        ws = new WebSocket("ws://echo.websocket.org");

        ws.OnOpen += OnOpenHandler;
        ws.OnMessage += OnMessageHandler;
        ws.OnClose += OnCloseHandler;

        stateMachine.AddHandler(State.Running, () => {
            new Wait(this, 3, () => {
                ws.ConnectAsync();
            });
        });

        stateMachine.AddHandler(State.Connected, () => {
            stateMachine.Transition(State.Ping);
        });

        stateMachine.AddHandler(State.Ping, () => {
            new Wait(this, 3, () => {
               ws.SendAsync("This WebSockets stuff is a breeze!", OnSendComplete);
            });
        });

        stateMachine.AddHandler(State.Pong, () => {
            new Wait(this, 3, () => {
                ws.CloseAsync();
            });
        });

        stateMachine.Run();
    }
예제 #2
0
    public void Close()
    {
        foreach (var completion in _pendingTasks)
        {
            completion.TrySetCanceled();
        }
        _pendingTasks.Clear();

        _socket.CloseAsync();
    }
예제 #3
0
 void Disconnect()
 {
     if (w == null)
     {
         Debug.Log("[Client] No websocket to disconnect.");
     }
     else
     {
         Debug.Log("[Client] Disconnect.");
         w.CloseAsync();
     }
 }
예제 #4
0
    private void unregister()
    {
        if (_socket != null)
        {
            _socket.OnOpen    -= open;
            _socket.OnClose   -= close;
            _socket.OnError   -= error;
            _socket.OnMessage -= message;

            _socket.CloseAsync(WebSocketSharp.CloseStatusCode.Undefined, null);
            _socket = null;
        }
    }
예제 #5
0
        public override Task CloseAsync(WebSocketCloseStatus closeStatus, string statusDescription, CancellationToken cancellationToken)
        {
            if (m_state != WebSocketState.Open)
            {
                throw new InvalidOperationException();
            }

            var closeTCS = new TaskCompletionSource <object>();

            try
            {
                m_connectCloseTCS = closeTCS;
                m_ws.CloseAsync();
            }
            catch (Exception ex)
            {
                closeTCS.SetException(new WebSocketException(0, ex));
            }

            return(closeTCS.Task);
        }
예제 #6
0
파일: WebSocket.cs 프로젝트: poup/MST
 /// <summary>
 /// Close websocket client connection
 /// </summary>
 /// <param name="code"></param>
 /// <param name="reason"></param>
 public void Close(string reason = "")
 {
     socket.CloseAsync(CloseStatusCode.Normal, reason);
 }