public void UpdateJoint() { string message = JSON.Method("SharedNumber", number); //Send the above message directly to the joint CometWorker.SendToAll(message); }
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(); }
public void GetServerTime() { string jsonMethod = JSON.Method("UpdateTime", DateTime.Now); CometWorker.SendToClient(_clientId, jsonMethod); CometWorker.SendToAll(jsonMethod); }
//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); }
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(); }
public void Dispose() { lock (Names) { Users.Remove(_clientID); Names.Remove(_username); } RenderMemberList(); CometWorker.SendToAll(JSON.Method("AppendToChat", "<strong>" + _username + " has left the building!</strong>")); }
static void UpdateClients() { while (true) { if (CometWorker.ActiveClientCount > 0) { CometWorker.SendToAll(JSON.Method("UpdateTime", DateTime.Now)); } Thread.Sleep(500); } }
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(); } }
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 + "');"); }
public void SendToAll(string message) { CometWorker.SendToAll(JSON.Method("s", message)); }
public void RenderMemberList() { CometWorker.SendToAll("GenerateMemberList('" + PokeIn.JSON.Tidy(UserList()) + "');"); }
public void Send(string message) { string json = PokeIn.JSON.Method("ChatMessageFrom", _username, message); CometWorker.SendToAll(json); }