Esempio n. 1
0
        /// <summary>
        ///     Handle any incoming request of the server.
        /// </summary>
        private async Task HandleRequests(HttpContext context, Func <Task> next)
        {
            if (context.Request.Path == "/connect_client")
            {
                if (context.WebSockets.IsWebSocketRequest)
                {
                    WebSocket socket = await context.WebSockets.AcceptWebSocketAsync();

                    networkView.Socket = socket;

                    //Start the simulation after n msec, we do this in parallel
                    //  so we don't block the await Receive and miss out on some receives.
                    //  Doing this syncronously will cause dropped packets.
                    Parallel.Invoke(StartSimulation);

                    await networkView.Receive();
                }
                else
                {
                    context.Response.StatusCode = 400;
                }
            }
            else
            {
                await next();
            }
        }