예제 #1
0
        private static void SocketServer_NewDataReceived(WebSocketSession session, byte[] value)
        {
            try
            {
                var request = WebSocketBlockWrite.ByteToPutFileRequest(value);

                switch (request.RequestType)
                {
                    case WebSocketRequestType.PutFileRequest:

                        PutFileResponse putFileResponse = new PutFileResponse
                        {
                            RequestId = request.RequestId,
                            ExecuteSuccess = true
                        };

                        session.Send(JsonConvert.SerializeObject(putFileResponse));
                        //var data = WebSocketBlockWrite.PutFileResponseToByte(putFileResponse);
                        //session.Send(data, 0, data.Length);

                        break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
예제 #2
0
 public static async Task Execute(ISession session, WebSocketSession webSocketSession, string requestID)
 {
     var allPokemonInBag = await session.Inventory.GetHighestsCp(1000);
     var list = new List<PokemonListWeb>();
     allPokemonInBag.ToList().ForEach(o => list.Add(new PokemonListWeb(o)));
     webSocketSession.Send(EncodingHelper.Serialize(new PokemonListResponce(list,requestID)));
 }
예제 #3
0
        private async void HandleMessage(WebSocketSession session, string message)
        {
            switch(message)
            {
                case "PokemonList":
                    await PokemonListTask.Execute(_session);
                    break;
                case "EggsList":
                    await EggsListTask.Execute(_session);
                    break;
                case "InventoryList":
                    await InventoryListTask.Execute(_session);
                    break;
            }

            // Setup to only send data back to the session that requested it. 
            try
            {
                dynamic decodedMessage = JObject.Parse(message);
                var handle = _websocketHandler?.Handle(_session, session, decodedMessage);
                if (handle != null)
                    await handle;
            }
            catch
            {
                // ignored
            }
        }
예제 #4
0
 public override void ExecuteCommand(WebSocketSession session, SubRequestInfo requestInfo)
 {
     foreach (var p in requestInfo.Body.Split(' '))
     {
         session.Send(p);
     }
 }
예제 #5
0
        void socketServer_SessionClosed(WebSocketSession session, CloseReason reason)
        {
            if (reason == CloseReason.ServerShutdown)
                return;

            SendToAll("System: " + session.Cookies["name"] + " disconnected");
        }
예제 #6
0
 static void OnMessage(WebSocketSession session, string message)
 {
     Write("Message: {0}", session, message);
     string audience = "http://persona/";
     PersonaClient client = new PersonaClient(message, audience, (PersonaResponse response) => OnPersonaResponse(session, response), (Exception exception) => OnPersonaException(session, exception));
     client.Run();
 }
예제 #7
0
 void secureSocketServer_NewSessionConnected(WebSocketSession session)
 {
     lock (m_SecureSessionSyncRoot)
     {
         m_SecureSessions.Add(session);
     }
 }
예제 #8
0
        void socketServer_NewSessionConnected(WebSocketSession session)
        {
            lock (m_SessionSyncRoot)
                m_Sessions.Add(session);

            SendToObserved("System: observe connected",session);
        }
예제 #9
0
 public override void ExecuteCommand(WebSocketSession session, StringCommandInfo commandInfo)
 {
     foreach(var p in commandInfo.Parameters)
     {
         session.SendResponse(p);
     }
 }
예제 #10
0
 void secureSocketServer_SessionClosed(WebSocketSession session, CloseReason reason)
 {
     lock (m_SecureSessionSyncRoot)
     {
         m_SecureSessions.Remove(session);
     }
 }
예제 #11
0
        private void HandleSession(WebSocketSession session)
        {
            if (_lastProfile != null)
                session.Send(Serialize(_lastProfile));

            if (_lastPokeStopList != null)
                session.Send(Serialize(_lastPokeStopList));
        }
예제 #12
0
파일: Program.cs 프로젝트: wsycarlos/ARIA
        static void appServer_SessionClosed(WebSocketSession session, CloseReason closeRs)
        {
            session.Close();
            Console.WriteLine("客户端" + session.RemoteEndPoint.Port + "断开了连接!");
            ClientNum -= 1;

            Console.WriteLine("客户端数目" + ClientNum.ToString());
        }
예제 #13
0
 private void SendToAll(WebSocketSession session, string msg)
 {
     //广播
     foreach (var sendSession in session.AppServer.GetAllSessions())
     {
         sendSession.Send(msg);
     }
 }
예제 #14
0
 private static dynamic InvokeHandler(WebSocketSession session, string command, string[] args)
 {
     if (CommandHandlers.ContainsKey(command))
     {
         return CommandHandlers[command].Invoke(session, args);
     }
     return false;
 }
예제 #15
0
 public override void ExecuteCommand(WebSocketSession session, SubRequestInfo requestInfo)
 {
     var paramsArray = requestInfo.Body.Split(' ');
     for (var i = 0; i < paramsArray.Length; i++)
     {
         session.Send(paramsArray[i]);
     }
 }
예제 #16
0
 private void _onNewMessageReceived(WebSocketSession underlyingSession, string message)
 {
     if (!IsUnderlyingSessionRegistered(underlyingSession))
     {
         RegisterSession(underlyingSession);
     }
     OnReceived(underlyingSession, message);
 }
        string buildJSONMessage(string message, string type, WebSocketSession session)
        {
            StringBuilder JSONMessage = new StringBuilder();

            JSONMessage = JSONMessage.AppendFormat("{{\"user\":\"{0}\",\"type\":\"{1}\",\"data\":\"{2}\"}}", session.Cookies["name"], type, message);

            return JSONMessage.ToString();
        }
예제 #18
0
 public static async Task Execute(ISession session, WebSocketSession webSocketSession, string requestID)
 {
     var playerStats = (await session.Inventory.GetPlayerStats()).FirstOrDefault();
     if (playerStats == null)
         return;
     var tmpData = new TrainerProfileWeb(session.Profile.PlayerData, playerStats);
     webSocketSession.Send(EncodingHelper.Serialize(new TrainerProfileResponce(tmpData, requestID)));
 }
예제 #19
0
 public static dynamic GetSessionUser(WebSocketSession session, params string[] args)
 {
     if (SessionDatas.ContainsKey(session.SessionID))
     {
         return SessionDatas[session.SessionID].Username;
     }
     return false;
 }
예제 #20
0
 static void HandleClient(WebSocketSession session)
 {
     while (session.Connected)
     {
         Write("Sending timestamp", session);
         session.Send(GetTimestamp());
         Thread.Sleep(1000);
     }
 }
예제 #21
0
        static void wsServer_NewMessageReceived(WebSocketSession session, string value)
        {
            Console.WriteLine("wsServer_NewMessageReceived: [" + value + "]");

            Console.WriteLine("will echo back ...");
            Thread.Sleep(1000);

            session.Send(value);
        }
예제 #22
0
        static void wsServer_NewDataReceived(WebSocketSession session, byte[] value)
        {
            Console.WriteLine("wsServer_NewDataReceived. Length= [" + value.Length + "]");

            Console.WriteLine("will echo back ...");
            Thread.Sleep(1000);

            session.Send(value, 0, value.Length);
        }
예제 #23
0
        public void socketServer_SessionClosed(WebSocketSession session, CloseReason reason)
        {
            lock (m_SessionSyncRoot)
                m_Sessions.Remove(session);

            if (reason == CloseReason.ServerShutdown)
                return;
            Console.WriteLine(session.ToString()+"connect disposed");
            //SendToAll("System: " + session.Cookies["name"] + " disconnected");
        }
예제 #24
0
 public static async Task Execute(ISession session, WebSocketSession webSocketSession, string requestID)
 {
     var settings = await session.Inventory.GetPokemonSettings();
     webSocketSession.Send(EncodingHelper.Serialize(new WebResponce()
     {
         Command = "PokemonSettings",
         Data = settings,
         RequestID = requestID
     }));
 }
        void socketServer_SessionClosed(WebSocketSession session, CloseReason reason)
        {
            lock (m_SessionSyncRoot)
                m_Sessions.Remove(session);

            Kinesis.gKinesis.StopSkeletonTracker();

            if (reason == CloseReason.ServerShutdown)
                return;
        }
예제 #26
0
 public  async Task Handle(ISession session, WebSocketSession webSocketSession, dynamic message)
 {
     if (_registerdHandlers.ContainsKey((string)message.Command))
     {
        await _registerdHandlers[(string)message.Command].Handle(session, webSocketSession, message);
     }
     else
     {
         // Unknown command.
     }
 }
예제 #27
0
 /// <summary>
 /// 创建连接
 /// </summary>
 /// <param name="session"></param>
 void ws_NewSessionConnected(WebSocketSession session)
 {
     //聊天连接时,则要向当前用户组中推送XX进行聊天
     //这时指定发送信息下拉中出现此人
     var path = GetSessionName(session);
     if (path.Equals("chat"))
     {
         //var msg = string.Format("{0}进入聊天");
         //SendToAll(session,msg);
     }
 }
예제 #28
0
        private static void appServer_NewMessageReceived(WebSocketSession session, string value)
        {
            //Console.WriteLine("LLEGO MENSAJE: " + value+", SESSION : "+ session.SessionID);

            String type = getMessageType(value);
            String mess = getReturnMessage(type);
            session.Send(mess);

            Console.WriteLine("recibo " + value);
            Console.WriteLine("envio  " + mess);
        }
예제 #29
0
        private static void SocketServer_NewSessionConnected(WebSocketSession session)
        {
            var authenticateResponse = new AuthenticationResponse
            {
                ExecuteSuccess = true,
                ServerFeatures = WebSocketServerFeature.Instance.GetFeatures()
            };

            session.Send(JsonConvert.SerializeObject(authenticateResponse));
            Console.WriteLine("Connection accepted");
        }
예제 #30
0
파일: Program.cs 프로젝트: wsycarlos/ARIA
        static void appServer_NewDataReceived(WebSocketSession session, byte[] value)
        {
            session.Send("欢迎登陆本系统LinMengUnity3DServer: ");

            Console.WriteLine("有客户端消息");

            Console.WriteLine("客户端数目" + ClientNum.ToString());
            foreach (var ses in session.AppServer.GetAllSessions())
            {
                ses.Send("给所有客户端广播发送的消息LinMeng广播电台");
            }
        }
예제 #31
0
파일: QUIT.cs 프로젝트: yqxflong/DashFire
 public override void ExecuteCommand(WebSocketSession session, SubRequestInfo requestInfo)
 {
     session.Close();
 }
예제 #32
0
파일: ChatServer.cs 프로젝트: lulzzz/OmniDB
 /// <summary>
 /// Handler called when a new client connects to the server.
 /// </summary>
 /// <param name="p_webSocketSession">The connection session.</param>
 private void NewSessionConnected(WebSocketSession p_webSocketSession)
 {
     lock (this.v_chatSessionsSyncRoot)
         this.v_chatSessions.Add(p_webSocketSession);
 }
예제 #33
0
 public static Task SendObject(this WebSocketSession session, object o)
 {
     return(session.SendTextMessage(JsonConvert.SerializeObject(o)));
 }
예제 #34
0
 public async Task Handle(ISession session, WebSocketSession webSocketSession, dynamic message)
 {
     await FavoritePokemonTask.Execute(session, (ulong)message.PokemonId, (bool)message.Favorite);
 }
예제 #35
0
 public Player(string name, WebSocketSession session)
 {
     id           = IdIncrement++;
     this.name    = name;
     this.session = session;
 }
예제 #36
0
 public override void HandleMessage(WebSocketSession session, string message)
 {
     throw new NotImplementedException();
 }
예제 #37
0
 protected void WebSocketServer_NewMessageReceived(WebSocketSession session, string e)
 {
     session.SendResponse(e);
 }
예제 #38
0
 public WebSocketUserInfo(string aLogin, WebSocketSession aWebSocketSession)
 {
     m_WebSocketSession = aWebSocketSession;
     this.Login         = aLogin;
 }
예제 #39
0
파일: Server.cs 프로젝트: encratite/TisTyme
 private void OnDisconnect(WebSocketSession session, CloseReason reason)
 {
     Write("Disconnected", session);
 }
예제 #40
0
파일: Main.cs 프로젝트: blindsight/Talker
		static void ws_NewDataReceived(WebSocketSession session, byte[] e)
		{
			session.Send("Data?");
		}
        public async Task Handle(ISession session, WebSocketSession webSocketSession, dynamic message)
        {
            await Logic.Tasks.HumanWalkSnipeTask.RemovePokemonFromQueue(session, (string)message.Id);

            await Task.Delay(1000);// Logic.Tasks.RecycleItemsTask.DropItem(session, (ItemId)message.ItemId, (int)message.Count);
        }
예제 #42
0
파일: Server.cs 프로젝트: encratite/TisTyme
 private void OnConnect(WebSocketSession session)
 {
     Write("Connected", session);
 }
예제 #43
0
        public override void ExecuteCommand(WebSocketSession session, SubRequestInfo requestInfo)
        {
            var paramArray = requestInfo.Body.Split(' ');

            session.Send((int.Parse(paramArray[0]) * int.Parse(paramArray[1])).ToString());
        }
예제 #44
0
 /// <summary>
 /// event handler for sessions disconnecting
 /// </summary>
 /// <param name="session"> the session that is disconnecting </param>
 /// <param name="close"> the reason why the session was closed </param>
 static void appServer_sessionClosed(WebSocketSession session, SuperSocket.SocketBase.CloseReason close)
 {
     sessionList.Remove(session); // remove the session from the session list
 }
예제 #45
0
파일: ChatServer.cs 프로젝트: lulzzz/OmniDB
        /// <summary>
        /// Handler called when a connection is closed.
        /// </summary>
        /// <param name="p_webSocketSession">The connection session.</param>
        /// <param name="p_reason">The reason why connection was closed.</param>
        private void SessionClosed(WebSocketSession p_webSocketSession, CloseReason p_reason)
        {
            lock (v_chatSessionsSyncRoot)
                this.v_chatSessions.Remove(p_webSocketSession);

            if (p_reason == CloseReason.ServerShutdown)
            {
                return;
            }

            WebSocketMessage v_response = new WebSocketMessage();

            if (!this.v_httpSessions.ContainsKey(p_webSocketSession.Cookies["user_id"]))
            {
                v_response.v_error = true;
                v_response.v_data  = "Session Object was destroyed. Please, restart the application.";
                SendToClient(p_webSocketSession, v_response);

                return;
            }

            Session v_httpSession = this.v_httpSessions[p_webSocketSession.Cookies["user_id"]];

            if (v_httpSession == null)
            {
                v_response.v_error = true;
                v_response.v_data  = "Session Object was destroyed. Please, restart the application.";
                SendToClient(p_webSocketSession, v_response);

                return;
            }

            OmniDatabase.Generic v_database = v_httpSession.v_omnidb_database;
            List <ChatUser>      v_userList = new List <ChatUser>();

            try
            {
                string v_onlineUsers = "";

                for (int i = 0; i < this.v_chatSessions.Count; i++)
                {
                    if (this.v_chatSessions[i].Cookies.ContainsKey("user_id"))
                    {
                        v_onlineUsers += this.v_chatSessions[i].Cookies["user_id"] + ", ";
                    }
                }

                v_onlineUsers = v_onlineUsers.Remove(v_onlineUsers.Length - 2);

                string v_sql =
                    "select x.*" +
                    "from (" +
                    "    select user_id, " +
                    "           user_name, " +
                    "           1 as online " +
                    "    from users " +
                    "    where user_id in ( " +
                    v_onlineUsers + ") " +
                    "     " +
                    "    union " +
                    "     " +
                    "    select user_id, " +
                    "           user_name, " +
                    "           0 as online " +
                    "    from users " +
                    "    where user_id not in ( " +
                    v_onlineUsers + ") " +
                    ") x " +
                    "order by x.online desc, x.user_name ";

                System.Data.DataTable v_table = v_database.v_connection.Query(v_sql, "chat_users");

                if (v_table != null && v_table.Rows.Count > 0)
                {
                    for (int i = 0; i < v_table.Rows.Count; i++)
                    {
                        ChatUser v_user = new ChatUser();

                        v_user.v_user_id     = int.Parse(v_table.Rows[i]["user_id"].ToString());
                        v_user.v_user_name   = v_table.Rows[i]["user_name"].ToString();
                        v_user.v_user_online = int.Parse(v_table.Rows[i]["online"].ToString());

                        v_userList.Add(v_user);
                    }
                }
            }
            catch (Spartacus.Database.Exception e)
            {
                v_response.v_error = true;
                v_response.v_data  = e.v_message.Replace("<", "&lt;").Replace(">", "&gt;").Replace(System.Environment.NewLine, "<br/>");
                SendToClient(p_webSocketSession, v_response);

                return;
            }

            v_response.v_code = (int)response.UserList;
            v_response.v_data = v_userList;
            SendToAllClients(v_response);
        }
예제 #46
0
        private void appServer_SessionClosed(WebSocketSession session, CloseReason value)
        {
//            Console.WriteLine();
//            Console.WriteLine("Client disconnected! Sessions counter: " + appServer.SessionCount);
        }
예제 #47
0
파일: Server.cs 프로젝트: encratite/TisTyme
 private void Write(string message, WebSocketSession session, params object[] arguments)
 {
     Console.WriteLine("{0} [{1}] {2}", GetTimestamp(), session.Host, string.Format(message, arguments));
 }
예제 #48
0
파일: ChatServer.cs 프로젝트: lulzzz/OmniDB
        /// <summary>
        /// Handler called when a new message from a client arrives to the server.
        /// </summary>
        /// <param name="p_webSocketSession">The connection session.</param>
        /// <param name="p_message">The message send by the client session.</param>
        private void NewMessageReceived(WebSocketSession p_webSocketSession, string p_message)
        {
            WebSocketMessage v_request = JsonConvert.DeserializeObject <WebSocketMessage>(p_message);

            if (v_request.v_code == (int)request.Login)
            {
                string v_userId = (string)v_request.v_data;

                if (!p_webSocketSession.Cookies.ContainsKey("user_id"))
                {
                    p_webSocketSession.Cookies.Add("user_id", v_userId);
                }
            }

            WebSocketMessage v_response = new WebSocketMessage();

            if (!this.v_httpSessions.ContainsKey(p_webSocketSession.Cookies["user_id"]))
            {
                v_response.v_error = true;
                v_response.v_data  = "Session Object was destroyed. Please, restart the application.";
                SendToClient(p_webSocketSession, v_response);

                return;
            }

            Session v_httpSession = this.v_httpSessions[p_webSocketSession.Cookies["user_id"]];

            if (v_httpSession == null)
            {
                v_response.v_error = true;
                v_response.v_data  = "Session Object was destroyed. Please, restart the application.";
                SendToClient(p_webSocketSession, v_response);

                return;
            }

            switch (v_request.v_code)
            {
            case (int)request.Login:
            {
                OmniDatabase.Generic v_database = v_httpSession.v_omnidb_database;
                List <ChatUser>      v_userList = new List <ChatUser>();

                try
                {
                    string v_onlineUsers = "";

                    for (int i = 0; i < this.v_chatSessions.Count; i++)
                    {
                        if (this.v_chatSessions[i].Cookies.ContainsKey("user_id"))
                        {
                            v_onlineUsers += this.v_chatSessions[i].Cookies["user_id"] + ", ";
                        }
                    }

                    v_onlineUsers = v_onlineUsers.Remove(v_onlineUsers.Length - 2);

                    string v_sql =
                        "select x.*" +
                        "from (" +
                        "    select user_id, " +
                        "           user_name, " +
                        "           1 as online " +
                        "    from users " +
                        "    where user_id in ( " +
                        v_onlineUsers + ") " +
                        "     " +
                        "    union " +
                        "     " +
                        "    select user_id, " +
                        "           user_name, " +
                        "           0 as online " +
                        "    from users " +
                        "    where user_id not in ( " +
                        v_onlineUsers + ") " +
                        ") x " +
                        "order by x.online desc, x.user_name ";

                    System.Data.DataTable v_table = v_database.v_connection.Query(v_sql, "chat_users");

                    if (v_table != null && v_table.Rows.Count > 0)
                    {
                        for (int i = 0; i < v_table.Rows.Count; i++)
                        {
                            ChatUser v_user = new ChatUser();

                            v_user.v_user_id     = int.Parse(v_table.Rows[i]["user_id"].ToString());
                            v_user.v_user_name   = v_table.Rows[i]["user_name"].ToString();
                            v_user.v_user_online = int.Parse(v_table.Rows[i]["online"].ToString());

                            v_userList.Add(v_user);
                        }
                    }
                }
                catch (Spartacus.Database.Exception e)
                {
                    v_response.v_error = true;
                    v_response.v_data  = e.v_message.Replace("<", "&lt;").Replace(">", "&gt;").Replace(System.Environment.NewLine, "<br/>");
                    SendToClient(p_webSocketSession, v_response);

                    return;
                }

                v_response.v_code = (int)response.UserList;
                v_response.v_data = v_userList;
                SendToAllClients(v_response);

                return;
            }

            case (int)request.GetOldMessages:
            {
                OmniDatabase.Generic v_database    = v_httpSession.v_omnidb_database;
                List <ChatMessage>   v_messageList = new List <ChatMessage>();

                try
                {
                    string v_sql =
                        "select mes.mes_in_code, " +
                        "       use.user_name, " +
                        "       mes.mes_st_text, " +
                        "       mes.mes_dt_timestamp, " +
                        "       mes.mes_bo_image " +
                        "from messages mes " +
                        "inner join messages_users meu " +
                        "           on mes.mes_in_code = meu.mes_in_code " +
                        "inner join users use " +
                        "           on mes.user_id = use.user_id " +
                        "where meu.user_id = " + v_httpSession.v_user_id + " " +
                        "order by meu.mes_in_code desc " +
                        "limit 20 offset " + v_request.v_data;

                    System.Data.DataTable v_table = v_database.v_connection.Query(v_sql, "chat_messages");

                    if (v_table != null && v_table.Rows.Count > 0)
                    {
                        for (int i = v_table.Rows.Count - 1; i >= 0; i--)
                        {
                            ChatMessage v_message = new ChatMessage();
                            v_message.v_message_id = int.Parse(v_table.Rows[i]["mes_in_code"].ToString());
                            v_message.v_user_name  = v_table.Rows[i]["user_name"].ToString();
                            v_message.v_text       = v_table.Rows[i]["mes_st_text"].ToString();
                            v_message.v_timestamp  = v_table.Rows[i]["mes_dt_timestamp"].ToString();
                            v_message.v_image      = int.Parse(v_table.Rows[i]["mes_bo_image"].ToString());

                            v_messageList.Add(v_message);
                        }
                    }
                }
                catch (Spartacus.Database.Exception e)
                {
                    v_response.v_error = true;
                    v_response.v_data  = e.v_message.Replace("<", "&lt;").Replace(">", "&gt;").Replace(System.Environment.NewLine, "<br/>");
                    SendToClient(p_webSocketSession, v_response);

                    return;
                }

                v_response.v_code = (int)response.OldMessages;
                v_response.v_data = v_messageList;
                SendToClient(p_webSocketSession, v_response);

                return;
            }

            case (int)request.SendText:
            {
                OmniDatabase.Generic v_database = v_httpSession.v_omnidb_database;
                string v_text = (string)v_request.v_data;

                ChatMessage v_message;

                try
                {
                    string v_sql =
                        "insert into messages (" +
                        "    mes_st_text, " +
                        "    mes_dt_timestamp, " +
                        "    user_id, " +
                        "    mes_bo_image " +
                        ") values ( " +
                        "  '" + v_text + "', " +
                        "    datetime('now', 'localtime'), " +
                        "  " + v_httpSession.v_user_id + ", " +
                        "    0 " +
                        ");" +
                        "select max(mes_in_code) " +
                        "from messages;";

                    int v_messsageCode = int.Parse(v_database.v_connection.ExecuteScalar(v_sql));

                    v_sql =
                        "insert into messages_users (" +
                        "    mes_in_code, " +
                        "    user_id " +
                        ")" +
                        "select " + v_messsageCode + ", " +
                        "    use.user_id " +
                        "from users use ";

                    v_database.v_connection.Execute(v_sql);

                    v_sql =
                        "select mes_dt_timestamp " +
                        "from messages " +
                        "where mes_in_code = " + v_messsageCode;

                    v_message = new ChatMessage();
                    v_message.v_message_id = v_messsageCode;
                    v_message.v_user_name  = v_httpSession.v_user_name;
                    v_message.v_text       = v_text;
                    v_message.v_timestamp  = v_database.v_connection.ExecuteScalar(v_sql);
                    v_message.v_image      = 0;
                }
                catch (Spartacus.Database.Exception e)
                {
                    v_response.v_error = true;
                    v_response.v_data  = e.v_message.Replace("<", "&lt;").Replace(">", "&gt;").Replace(System.Environment.NewLine, "<br/>");
                    SendToClient(p_webSocketSession, v_response);

                    return;
                }

                v_response.v_code = (int)response.NewMessage;
                v_response.v_data = v_message;
                SendToAllClients(v_response);

                return;
            }

            case (int)request.Writing:
            {
                v_response.v_code = (int)response.UserWriting;
                v_response.v_data = v_httpSession.v_user_id;
                SendToAllClients(v_response);

                return;
            }

            case (int)request.NotWriting:
            {
                v_response.v_code = (int)response.UserNotWriting;
                v_response.v_data = v_httpSession.v_user_id;
                SendToAllClients(v_response);

                return;
            }

            case (int)request.SendImage:
            {
                OmniDatabase.Generic v_database = v_httpSession.v_omnidb_database;
                string v_url = (string)v_request.v_data;

                ChatMessage v_message;

                try
                {
                    string v_sql =
                        "insert into messages (" +
                        "    mes_st_text, " +
                        "    mes_dt_timestamp, " +
                        "    user_id, " +
                        "    mes_bo_image " +
                        ") values ( " +
                        "  '" + v_url + "', " +
                        "    datetime('now', 'localtime'), " +
                        "  " + v_httpSession.v_user_id + ", " +
                        "    1 " +
                        ");" +
                        "select max(mes_in_code) " +
                        "from messages;";

                    int v_messsageCode = int.Parse(v_database.v_connection.ExecuteScalar(v_sql));

                    v_sql =
                        "insert into messages_users (" +
                        "    mes_in_code, " +
                        "    user_id " +
                        ")" +
                        "select " + v_messsageCode + ", " +
                        "    use.user_id " +
                        "from users use ";

                    v_database.v_connection.Execute(v_sql);

                    v_sql =
                        "select mes_dt_timestamp " +
                        "from messages " +
                        "where mes_in_code = " + v_messsageCode;

                    v_message = new ChatMessage();
                    v_message.v_message_id = v_messsageCode;
                    v_message.v_user_name  = v_httpSession.v_user_name;
                    v_message.v_text       = v_url;
                    v_message.v_timestamp  = v_database.v_connection.ExecuteScalar(v_sql);
                    v_message.v_image      = 1;
                }
                catch (Spartacus.Database.Exception e)
                {
                    v_response.v_error = true;
                    v_response.v_data  = e.v_message.Replace("<", "&lt;").Replace(">", "&gt;").Replace(System.Environment.NewLine, "<br/>");
                    SendToClient(p_webSocketSession, v_response);

                    return;
                }

                v_response.v_code = (int)response.NewMessage;
                v_response.v_data = v_message;
                SendToAllClients(v_response);

                return;
            }
            }

            /*Thread v_sendResponse = new Thread(SendResponse);
            *  v_sendResponse.Start((Object)p_webSocketSession);*/
        }
예제 #49
0
 /// <summary>
 /// 有新连接时触发
 /// </summary>
 /// <param name="aobjSocketSession">用户连接Session</param>
 private void HandlerNewSessionConnected(WebSocketSession aobjSocketSession)
 {
     gobjUserSession.Add(aobjSocketSession.SessionID, aobjSocketSession);
 }
예제 #50
0
        private void appServer_NewSessionConnected(WebSocketSession session)
        {
//            Console.WriteLine();
//            Console.WriteLine("New session connected! Sessions counter: " + appServer.SessionCount);
//            session.Send("Hello new client!");
        }
예제 #51
0
 public static async Task <dynamic> ReceiveObject(this WebSocketSession session)
 {
     return(JObject.Parse(await session.ReceiveTextMessage()));
 }
예제 #52
0
 /// <summary>
 ///     Called when the socket client recieves a message
 /// </summary>
 private static void socket_RecieveMessage(WebSocketSession session, string value)
 {
     EmitMessageFromSocket(value);
 }
예제 #53
0
        private void appServer_NewMessageReceived(WebSocketSession session, string message)
        {
//            Console.WriteLine("Client said: " + message);
            //Send the received message back
//            session.Send("Server responded back: " + message);
        }
예제 #54
0
파일: ChatServer.cs 프로젝트: lulzzz/OmniDB
 /// <summary>
 /// Sends a message to the client that generated the request.
 /// </summary>
 /// <param name="p_webSocketSession">The connection session.</param>
 /// <param name="p_message">The message to be send to the client.</param>
 private void SendToClient(WebSocketSession p_webSocketSession, WebSocketMessage p_message)
 {
     p_webSocketSession.Send(JsonConvert.SerializeObject(p_message));
 }
예제 #55
0
 protected void WebSocketServer_NewDataReceived(WebSocketSession session, byte[] e)
 {
     session.SendResponse(e);
 }
예제 #56
0
 /// <summary>
 /// Initializes a widget.
 /// </summary>
 /// <param name="session">The session to initialize the widget for.</param>
 public override void Init(WebSocketSession session)
 {
     SendUpdate(session);
 }
예제 #57
0
        protected override void processReceivedJSONMessage(string receivedJSONmode, string message, WebSocketSession session)
        {
            var sessionparam = (SSMCOMWebsocketSessionParam)session.Items["Param"];

            switch (receivedJSONmode)
            {
            //SSM COM all reset
            case (ResetJSONFormat.ModeCode):
                sessionparam.reset();
                send_response_msg(session, "SSMCOM session RESET. All send parameters are disabled.");
                break;

            case (SSMCOMReadJSONFormat.ModeCode):
                SSMCOMReadJSONFormat msg_obj_ssmread = JsonConvert.DeserializeObject <SSMCOMReadJSONFormat>(message);
                msg_obj_ssmread.Validate();

                SSMParameterCode target_code = (SSMParameterCode)Enum.Parse(typeof(SSMParameterCode), msg_obj_ssmread.code);
                bool             flag        = msg_obj_ssmread.flag;

                if (msg_obj_ssmread.read_mode == SSMCOMReadJSONFormat.FastReadModeCode)
                {
                    sessionparam.FastSendlist[target_code] = flag;
                }
                else
                {
                    sessionparam.SlowSendlist[target_code] = flag;
                }
                send_response_msg(session, "SSMCOM session read flag for : " + target_code.ToString() + " read_mode :" + msg_obj_ssmread.read_mode + " set to : " + flag.ToString());
                break;

            case (SSMSLOWREADIntervalJSONFormat.ModeCode):
                SSMSLOWREADIntervalJSONFormat msg_obj_interval = JsonConvert.DeserializeObject <SSMSLOWREADIntervalJSONFormat>(message);
                msg_obj_interval.Validate();
                ssmcom1.SlowReadInterval = msg_obj_interval.interval;

                send_response_msg(session, "SSMCOM slowread interval to : " + msg_obj_interval.interval.ToString());
                break;

            default:
                throw new JSONFormatsException("Unsuppoted mode property.");
            }
        }
예제 #58
0
 static void appServer_NewMessageReceived(WebSocketSession session, string message)
 {
     //Send the received message back
     session.Send("Server: " + message);
 }
예제 #59
0
파일: Main.cs 프로젝트: blindsight/Talker
		static void ws_NewMessageReceived(WebSocketSession session, string e)
		{
			User userObj = Server.FindClientBySessionId(session.SessionID);
			HandleClientCommunication(userObj, e);
		}
예제 #60
0
파일: Server.cs 프로젝트: encratite/TisTyme
 private void OnMessage(WebSocketSession session, string message)
 {
     Write("Message: {0}", session, message);
 }