示例#1
0
        public void UpdateJoint()
        {
            string message = JSON.Method("SharedNumber", number);

            //Send the above message directly to the joint
            CometWorker.SendToAll(message);
        }
示例#2
0
        public void SetName(string userName)
        {
            if (_username != "")
            {
                CometWorker.SendToClient(_clientID, "alert('You already have a username!');");
                return;
            }
            lock (Names)
            {
                if (Names.ContainsKey(userName))
                {
                    CometWorker.SendToClient(_clientID, "alert('Another user is using the name you choose! Please try another one.');");
                    return;
                }
                else
                {
                    Names.Add(userName, _clientID);
                    Users.Add(_clientID, userName);
                    _username = userName;
                }
            }

            CometWorker.SendToClient(_clientID, JSON.Method("UsernameSet", PokeIn.JSON.Tidy(userName)));
            CometWorker.SendToAll(JSON.Method("AppendToChat", "<strong>" + PokeIn.JSON.Tidy(userName) + " has enterred the building!</strong>"));
            RenderMemberList();
        }
示例#3
0
        public void GetServerTime()
        {
            string jsonMethod = JSON.Method("UpdateTime", DateTime.Now);

            CometWorker.SendToClient(_clientId, jsonMethod);
            CometWorker.SendToAll(jsonMethod);
        }
示例#4
0
文件: ChatApp.cs 项目: itsjw/test-2
        //When PokeIn sees ChatMessage custom class as a parameter, it automaticly defines ChatMessage JS class on client side.
        public void Send(ChatMessage message)
        {
            //Create JSON method from custom class
            string json = JSON.Method("ChatMessageFrom", message); //ChatMessageFrom( {Username:'******', Message:'message' } );

            CometWorker.SendToAll(json);
        }
示例#5
0
文件: WCFSample.cs 项目: itsjw/test-2
        static void CheckMessages()
        {
            PokeInWCFMessageFormat[] results = null;

            try
            {
                results = proxy.PingMessages();
            }
            catch (System.Net.WebException e)
            {
                ServerConnected = false;
                CometWorker.SendToAll("UpdateServiceStatus(" + ServerConnected.ToString().ToLower() + ");");
                ConnectToWCF();
            }
            if (results != null)
            {
                if (results.Length > 0)
                {
                    foreach (PokeInWCFMessageFormat message in results)
                    {
                        CometWorker.SendToClients(message.Clients, message.Message);
                    }
                }
            }

            //check messages every 1 second
            //You may implement a WCF instance to both side for efficiency or check out the Multiple Server sample project
            Thread.Sleep(1000);
            CheckMessages();
        }
示例#6
0
 public void Dispose()
 {
     lock (Names)
     {
         Users.Remove(_clientID);
         Names.Remove(_username);
     }
     RenderMemberList();
     CometWorker.SendToAll(JSON.Method("AppendToChat", "<strong>" + _username + " has left the building!</strong>"));
 }
示例#7
0
文件: Notifier.cs 项目: itsjw/test-2
 static void UpdateClients()
 {
     while (true)
     {
         if (CometWorker.ActiveClientCount > 0)
         {
             CometWorker.SendToAll(JSON.Method("UpdateTime", DateTime.Now));
         }
         Thread.Sleep(500);
     }
 }
示例#8
0
文件: WCFSample.cs 项目: itsjw/test-2
        static void ConnectToWCF()
        {
            try
            {
                proxy = new localhost.PokeInWCF();
                bool b;
                proxy.PingAlive(out b, out b);

                ServerConnected = true;

                /* ConnectToWCF method call
                 * made by static constructor or CheckMessage function?
                 *
                 * Check, if there is an existing worker thread
                 */
                if (workerThread == null)
                {
                    workerThread = new System.Threading.Thread(CheckMessages);
                    workerThread.Start();
                }

                CometWorker.SendToAll("UpdateServiceStatus(" + ServerConnected.ToString().ToLower() + ");");

                string[] clientIds = CometWorker.GetClientIds();
                if (clientIds != null)
                {
                    proxy.AddClients(clientIds);
                }
            }
            catch
            {
                //Connection Issue re-try after 1.5 secs
                Thread.Sleep(1500);
                ConnectToWCF();
            }
        }
示例#9
0
 public void TestString(string str)
 {
     str = JSON.Tidy(str);//to make sure that the string is ready for proper transfer
     CometWorker.SendToClient(_clientId, "UpdateString('" + str + "');");
     CometWorker.SendToAll("UpdateString('" + str + "');");
 }
示例#10
0
 public void SendToAll(string message)
 {
     CometWorker.SendToAll(JSON.Method("s", message));
 }
示例#11
0
 public void RenderMemberList()
 {
     CometWorker.SendToAll("GenerateMemberList('" + PokeIn.JSON.Tidy(UserList()) + "');");
 }
示例#12
0
        public void Send(string message)
        {
            string json = PokeIn.JSON.Method("ChatMessageFrom", _username, message);

            CometWorker.SendToAll(json);
        }