public async void Open(string url, string protocol = null, string authToken = null)
        {
            try
            {
                if (_websocket != null)
                {
                    EndConnection();
                }

                _websocket                  = new WebSocketWrapper();
                _websocket.Closed          += _websocket_Closed;
                _websocket.Opened          += _websocket_Opened;
                _websocket.Error           += _websocket_Error;
                _websocket.MessageReceived += _websocket_MessageReceived;

                if (url.StartsWith("https"))
                {
                    url = url.Replace("https://", "wss://");
                }
                else if (url.StartsWith("http"))
                {
                    url = url.Replace("http://", "ws://");
                }

                await _websocket.Connect(url, protocol, authToken);
            }
            catch (Exception ex)
            {
                OnError(ex.Message);
            }
        }
        public async void Open(string url, string protocol = null, string authToken = null)
        {
            try
            {
                if (_websocket != null)
                    EndConnection();

                _websocket = new WebSocketWrapper();
                _websocket.Closed += _websocket_Closed;
                _websocket.Opened += _websocket_Opened;
                _websocket.Error += _websocket_Error;
                _websocket.MessageReceived += _websocket_MessageReceived;

                if (url.StartsWith("https"))
                    url = url.Replace("https://", "wss://");
                else if (url.StartsWith("http"))
                    url = url.Replace("http://", "ws://");
                
                await _websocket.Connect(url, protocol, authToken);

            }
            catch (Exception ex)
            {
                OnError(ex.Message);
            }
        }
        //
        void EndConnection()
        {
            if (_websocket != null)
            {
                _websocket.Closed          -= _websocket_Closed;
                _websocket.Opened          -= _websocket_Opened;
                _websocket.Error           -= _websocket_Error;
                _websocket.MessageReceived -= _websocket_MessageReceived;
                _websocket.Dispose();
                _websocket = null;

                IsOpen = false;
                OnClosed();
            }
        }
 void _websocket_Closed(WebSocketWrapper arg)
 {
     EndConnection();
 }
 void _websocket_MessageReceived(string m, WebSocketWrapper arg)
 {
     OnMessage(m);
 }
 void _websocket_Opened(WebSocketWrapper arg)
 {
     IsOpen = true;
     OnOpened();
 }
        //
        void EndConnection()
        {
            if (_websocket != null)
            {
                _websocket.Closed -= _websocket_Closed;
                _websocket.Opened -= _websocket_Opened;
                _websocket.Error -= _websocket_Error;
                _websocket.MessageReceived -= _websocket_MessageReceived;
                _websocket.Dispose();
                _websocket = null;

                IsOpen = false;
                OnClosed();
            }
        }
 void _websocket_Closed(WebSocketWrapper arg)
 {
     EndConnection();
 }
        void _websocket_MessageReceived(string m, WebSocketWrapper arg)
        {

            OnMessage(m);
        }
        void _websocket_Opened(WebSocketWrapper arg)
        {

            IsOpen = true;
            OnOpened();
        }
Example #11
0
 void _websocket_DataReceived(byte[] data, WebSocketWrapper arg)
 {
     OnData(data);
 }
 void _websocket_MessageReceived(MessageEventArgs m, WebSocketWrapper arg)
 {
     OnMessage(this, m);
 }
 void _websocket_Opened(WebSocketWrapper arg)
 {
     IsOpen = true;
     OnOpened(this, new EventArgs());
 }