Exemple #1
0
 public void ProcessRequest(HttpContext context)
 {
     if (context.IsWebSocketRequest)
     {
         context.AcceptWebSocketRequest(new ServerEventHandler());
     }
 }
Exemple #2
0
 public void ProcessRequest(HttpContext context)
 {
     if (context.IsWebSocketRequest || context.IsWebSocketRequestUpgrading)
     {
         context.AcceptWebSocketRequest(new MyWSHandler());
     }
 }
Exemple #3
0
 public void ProcessRequest(HttpContext context)
 {
     if (context.IsWebSocketRequest)
     {
         context.AcceptWebSocketRequest(new MyWebSocketHandle());
     }
 }
Exemple #4
0
 public void ProcessRequest(HttpContext context)
 {
     if (context.IsWebSocketRequest)
     {
         context.AcceptWebSocketRequest(RepeatCloseWebSocket);
     }
 }
Exemple #5
0
 public void ProcessRequest(HttpContext context)
 {
     if (context.IsWebSocketRequest || context.IsWebSocketRequestUpgrading) //Проверка на веб сокет соединение!
     {
         context.AcceptWebSocketRequest(new MyWebSocket());                 //Передача управления в обработчик клиента
     }
 }
Exemple #6
0
 public void ProcessRequest(HttpContext context)
 {
     if (context.IsWebSocketRequest)
     {
         context.AcceptWebSocketRequest(new RemoteSessionSocketHandler(context.Session, string.IsNullOrEmpty(context.Request["type"]) ? true : context.Request["type"] == "binary"));
     }
 }
Exemple #7
0
            public JoinStatus TryAddPlayer(HttpContext context, string playerName, int maxPlayers)
            {
                lock (_sync)
                {
                    if (_players.Count >= maxPlayers)
                    {
                        return(JoinStatus.RoomFull);
                    }
                    if (_players.ContainsKey(playerName))
                    {
                        return(JoinStatus.NameInUse);
                    }

                    var player   = new Player(this, playerName);
                    var joinData = new JObject
                    {
                        { "name", playerName }
                    };

                    Broadcast(GetMessage("join", joinData));
                    _players.Add(playerName, player);
                    context.AcceptWebSocketRequest(player.Accept);
                    player.Send(Serialize(GetMessage("init", GetInitData())));
                    return(JoinStatus.Success);
                }
            }
Exemple #8
0
 /// <summary>
 /// 限制用户登录
 /// </summary>
 public void WebSocketService()
 {
     if (HttpContext.IsWebSocketRequest)
     {
         HttpContext.AcceptWebSocketRequest(AsyncUserLimit);
     }
 }
Exemple #9
0
 public void ProcessRequest(HttpContext context)
 {
     if (context.IsWebSocketRequest)
     {
         context.AcceptWebSocketRequest(new CacheHubHandler());
     }
 }
Exemple #10
0
 public void ProcessRequest(HttpContext context)
 {
     if (context.IsWebSocketRequest)
     {
         context.AcceptWebSocketRequest(new WebSocketConfPubHandler(context.Request.ServerVariables["REMOTE_ADDR"]));
     }
 }
Exemple #11
0
        //Overriden menthod Process Request async/await featur has been used.
        public override async Task ProcessRequestAsync(HttpContext httpContext)
        {
            //task is executed
            await Task.Run(() =>
            {
                //Checks if it is a Web Socket Request
                if (httpContext.IsWebSocketRequest)
                {
                    httpContext.AcceptWebSocketRequest(async delegate(AspNetWebSocketContext aspNetWebSocketContext)
                    {
                        Socket = aspNetWebSocketContext.WebSocket;

                        //Checks if the connection is not already closed
                        while (Socket != null || Socket.State != WebSocketState.Closed)
                        {
                            //Recieves the message from client
                            ArraySegment <byte> buffer = new ArraySegment <byte>(new byte[1024]);
                            WebSocketReceiveResult webSocketReceiveResult = await Socket.ReceiveAsync(buffer, CancellationToken.None);

                            //Here i have handled the case of text based communication, you can also put down your hode to handle byte arrays etc.
                            switch (webSocketReceiveResult.MessageType)
                            {
                            case WebSocketMessageType.Text:
                                OnMessageReceived(Encoding.UTF8.GetString(buffer.Array, 0, webSocketReceiveResult.Count));
                                break;
                            }
                        }
                    });
                }
            });
        }
 public void ProcessRequest(HttpContext context)
 {
     if (context.IsWebSocketRequest)
     {
         context.AcceptWebSocketRequest(new SessionEventGameSocket());
     }
 }
Exemple #13
0
        public void ProcessRequest(HttpContext context)
        {
            WebSupport.InitializeContextStorage(context.Request);
            bool isSocket = false;

            if (context.IsWebSocketRequest)
            {
                isSocket = true;
            }
            if (context.IsWebSocketRequest)
            {
                context.AcceptWebSocketRequest(HandleWebSocket);
            }
            else
            {
                context.Response.StatusCode = 400;
            }

            /*
             * WebSupport.InitializeContextStorage(context.Request);
             * try
             * {
             *  if (request.Path.StartsWith(AuthEmailValidation))
             *  {
             *      HandleEmailValidation(context);
             *  }
             * } finally
             * {
             *  InformationContext.ProcessAndClearCurrent();
             * }*/
        }
Exemple #14
0
 public void ProcessRequest(HttpContext context)
 {
     if (context.IsWebSocketRequest)
     {
         context.AcceptWebSocketRequest(new WebSocketConfSubHandler(context.Request.QueryString["room"], context.Request.ServerVariables["REMOTE_ADDR"], context.Request.ServerVariables["REMOTE_PORT"]));
     }
 }
Exemple #15
0
 public void SocketHandle()
 {
     if (HttpContext.IsWebSocketRequest)
     {
         HttpContext.AcceptWebSocketRequest(ProcessWS);
     }
 }
Exemple #16
0
 /// <summary>
 /// Process the request
 /// </summary>
 /// <param name="context"></param>
 public void ProcessRequest(HttpContext context)
 {
     if (context.IsWebSocketRequest)
     {
         context.AcceptWebSocketRequest(ProcessCommunication);
     }
 }
Exemple #17
0
 public void ProcessRequest(HttpContext context)
 {
     GlobalCommon.Logger.WriteLog(LoggerLevel.DEBUG, string.Format("Before {0} Process Request Memory:{1}", context.Request.Url, ComFunc.GetProcessUsedMemory()));
     _context = context;
     if (IsWebSocket)
     {
         context.AcceptWebSocketRequest(ProcessWebSocket);
     }
     else
     {
         WP p = Activator.CreateInstance <WP>();
         WD d = Activator.CreateInstance <WD>();
         try
         {
             Init(context, p, d);
             this.StepStart(p, d);
             AfterProcess(context, p, d);
         }
         catch (Exception ex)
         {
             OnError(ex, p, d);
         }
         finally
         {
             //释放hostjsview
             //var hjv = (HostJsView)p.ExtentionObj.hostviewengine;
             //hjv.Release();
             p.Dispose();
             d.Dispose();
             GC.Collect();
         }
     }
     GlobalCommon.Logger.WriteLog(LoggerLevel.DEBUG, string.Format("After {0} Process Request Memory:{1}", context.Request.Url, ComFunc.GetProcessUsedMemory()));
 }
 public void ProcessRequest(HttpContext context)
 {
     if (context.IsWebSocketRequest)
     {
         context.AcceptWebSocketRequest(ChatMessageService.WebSocketChatMessages);
     }
 }
Exemple #19
0
 public void ProcessRequest(HttpContext context)
 {
     if (context.IsWebSocketRequest) //можно проверить является ли пришедший запрос запросом на соед по протоколу вебсок
     {
         context.AcceptWebSocketRequest(WebSocketRequest);
     }
 }
        /// <summary>
        /// WebSocket处理
        /// </summary>
        /// <param name="context"></param>
        public void WebSocketProc(HttpContext context)
        {
            if (null != context && context.IsWebSocketRequest)
            {
                context.AcceptWebSocketRequest(async p =>
                {
                    var socket = p.WebSocket;
                    clientSockList.Add(socket);
                    //进入一个无限循环,当web socket close是循环结束
                    while (true)
                    {
                        var buffer         = new ArraySegment <byte>(new byte[1024]);
                        var receivedResult = await socket.ReceiveAsync(buffer, CancellationToken.None);//对web socket进行异步接收数据
                        if (receivedResult.MessageType == WebSocketMessageType.Close)
                        {
                            await socket.CloseAsync(WebSocketCloseStatus.Empty, string.Empty, CancellationToken.None);//如果client发起close请求,对client进行ack
                            break;
                        }

                        if (socket.State == System.Net.WebSockets.WebSocketState.Open)
                        {
                            string recvMsg = Encoding.UTF8.GetString(buffer.Array, 0, receivedResult.Count) + "来自服务器" + DateTime.Now;
                            var recvBytes  = Encoding.UTF8.GetBytes(recvMsg);
                            var sendBuffer = new ArraySegment <byte>(recvBytes);

                            await socket.SendAsync(sendBuffer, WebSocketMessageType.Text, true, CancellationToken.None);
                        }
                    }
                });
            }
        }
 /// <summary>
 /// 监听WebSocket
 /// </summary>
 /// <param name="context">HttpContext</param>
 /// <param name="userName">用户名称</param>
 public void Monitor(HttpContext context, string userName)
 {
     if (context.IsWebSocketRequest)
     {
         context.AcceptWebSocketRequest((c) => ProcessChat(c, userName));
     }
 }
 public void ProcessRequest(HttpContext context)
 {
     if (context.IsWebSocketRequest)
     {
         context.AcceptWebSocketRequest(new ChatWebsocket());
     }
 }
 public void ProcessRequest(HttpContext context)
 {
     //context.Response.AddHeader("Access-Control-Allow-Origin", "*");
     if (context.IsWebSocketRequest || context.IsWebSocketRequestUpgrading)
     {
         #region CHECK ACCOUNT LOGIN
         accountInfo = Account.GetAccountInfo(context);
         if (accountInfo == null)
         {
             return;
         }
         #endregion
         ServerSocket dataServer = new ServerSocket();
         dataServer.userData = new Server.Packet.Users()
         {
             userId   = accountInfo.AccountId.ToString(),
             email    = accountInfo.Email,
             userName = accountInfo.UserName,
             avatar   = accountInfo.Avatar,
             token    = accountInfo.Token,
             tokenOld = ""
         };
         context.AcceptWebSocketRequest(dataServer.Receiver);
     }
 }
 public void ProcessRequest(HttpContext context)
 {
     if (context.IsWebSocketRequest)
     {
         context.AcceptWebSocketRequest(new MicrosoftWebSockets());
     }
 }
 /// <summary>
 /// 入口
 /// </summary>
 /// <param name="context"></param>
 public void ProcessRequest(HttpContext context)
 {
     if (context.IsWebSocketRequest)
     {
         context.AcceptWebSocketRequest(ChatManager.Start);
     }
 }
Exemple #26
0
 public void ProcessRequest(HttpContext context)
 {
     if (context.IsWebSocketRequest)
     {
         context.AcceptWebSocketRequest(DoRespond);
     }
 }
Exemple #27
0
 private static Dictionary <string, WebSocket> CONNECT_POOL = new Dictionary <string, WebSocket>();      //用户连接池
 public void ProcessRequest(HttpContext context)
 {
     if (context.IsWebSocketRequest)
     {
         context.AcceptWebSocketRequest(ProcessChat);
     }
 }
Exemple #28
0
 public async Task  ProcessRequest(HttpContext context)
 {
     if (context.IsWebSocketRequestUpgrading)
     {
         context.AcceptWebSocketRequest(GetBlockChainRequestHandler);
     }
 }
 public void ProcessRequest(HttpContext context)
 {
     if (context.IsWebSocketRequest)
     {
         var jwToken = context.Request.QueryString["Bearer"];
         context.AcceptWebSocketRequest(HandleWebSocket);
     }
 }
Exemple #30
0
 public void ProcessRequest(HttpContext context)
 {
     //Если запрос является запросом веб сокета
     if (context.IsWebSocketRequest)
     {
         context.AcceptWebSocketRequest(WebSocketRequest);
     }
 }