Esempio n. 1
0
 private void DisposeSocket()
 {
     try
     {
         if (SocketHandler != null)
         {
             SocketHandler.MessageReceived    -= SocketHandler_MessageReceived;
             SocketHandler.ClientDisconnected -= SocketHandler_ClientDisconnected;
             SocketHandler?.Dispose();
             SocketHandler = null;
         }
     }
     catch { }
 }
Esempio n. 2
0
        private async Task <bool> TryConnect()
        {
            try
            {
                var tcp = new ClientWebSocket();
                await tcp.ConnectAsync(new Uri(Address), new CancellationToken());

                DisposeSocket();
                SocketHandler = new SocketHandler(tcp);
                SocketHandler.MessageReceived    += SocketHandler_MessageReceived;
                SocketHandler.ClientDisconnected += SocketHandler_ClientDisconnected;
                Recieve();
                return(true);
            }
            catch (Exception ex)
            {
                LogEngine.Error(ex);
                return(false);
            }
        }