private static void HandleClientThread()
        {
            while (!cancellation.IsCancellationRequested)
            {
                Context context = null;

                while (NewClients.Count == 0)
                {
                    Thread.Sleep(10);
                    if (cancellation.IsCancellationRequested)
                    {
                        return;
                    }
                }

                lock (NewClients)
                {
                    if (NewClients.Count == 0)
                    {
                        continue;
                    }

                    context = NewClients.Dequeue();
                }

                lock (ContextMapping)
                {
                    WebSocketClient client = ContextMapping[context];
                    client.SetupContext(context);
                }
            }
        }
Esempio n. 2
0
        private static void HandleClientThread()
        {
            while (true)
            {
                Context context = null;

                while (NewClients.Count == 0)
                {
                    Thread.Sleep(10);
                }

                lock (NewClients)
                {
                    if (NewClients.Count == 0)
                    {
                        continue;
                    }

                    context = NewClients.Dequeue();
                }

                lock (ContextMapping)
                {
                    WebSocketClient client = ContextMapping[context];
                    client.SetupContext(context);
                }
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            NewClients = await _context.NewClients.FirstOrDefaultAsync(m => m.ID == id);

            if (NewClients == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Esempio n. 4
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            NewClients = await _context.NewClients.FindAsync(id);

            if (NewClients != null)
            {
                _context.NewClients.Remove(NewClients);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Esempio n. 5
0
        /// <summary>
        /// Fires when a client connects.
        /// </summary>
        /// <param name="result">null</param>
        protected void OnRunClient(IAsyncResult result)
        {
            bool connectError = false;

            try
            {
                _client.EndConnect(result);
            }
            catch
            {
                Disconnect();
                connectError = true;
            }

            using (_context = new Context(null, _client))
            {
                _context                       = new Context(null, _client);
                _context.BufferSize            = 512;
                _context.UserContext.DataFrame = new DataFrame();
                _context.UserContext.SetOnConnect(OnConnect);
                _context.UserContext.SetOnConnected(OnConnected);
                _context.UserContext.SetOnDisconnect(OnDisconnect);
                _context.UserContext.SetOnSend(OnSend);
                _context.UserContext.SetOnReceive(OnReceive);
                _context.UserContext.OnConnect();

                if (connectError)
                {
                    _context.UserContext.OnDisconnect();
                    return;
                }

                lock (ContextMapping)
                {
                    ContextMapping[_context] = this;
                }

                lock (NewClients)
                {
                    NewClients.Enqueue(_context);
                }
            }
        }