public override void SendData(SocketMessage message) { // FIXME... execute a broadcast }
internal void ProcessMessage(SocketClient client, SocketMessage message) { if (message != null) { switch (message.Command.ToLower()) { case "set": this.Store(message); if (message.ToID == -1) { this.Broadcast(message); } break; case "get": lock (this.memCache) { client.SendValue(this.Get(message.Member), -1); } break; case "get-all": lock (this.memCache) { foreach (KeyValuePair<string, SocketValue> entry in this.memCache) { SocketValue val = entry.Value; client.SendValue(entry.Value, message.FromID); } } break; default: break; } message = null; } }
protected void Store(SocketMessage message) { string member = message.Member; lock(this.memCache) { if (MemberExists(member)) { this.memCache[member].SourceID = message.FromID; this.memCache[member].Data = message.Data; } } }
public void Broadcast(SocketMessage message) { lock (this.clients) { foreach (SocketClient client in this.clients) { client.SendData(message); } } }
private bool ProcessMessage(SocketMessage message) { try { if (message != null) { switch (message.Command) { case "startup": this.initilized = true; return true; case "echo": this.PingReciveEcho(message); return true; case "ping": this.PingSendEcho(message); return true; case "set": this.Store(message); //this.OnMessageRecived(message); return (message.ToID == this.ID); case "get": if (this.IsHost) return false; // allow parent to respond to "get" commands this.SendData("set", message.Member, this.GetValue(message.Member), message.FromID); //this.OnMessageRecived(message); return true; case "get-all": if (this.IsHost) return false; // allow parent to respond to "get" commands return true; default: //this.OnMessageRecived(message); break; } return false; } } catch { } return true; }
public abstract void SendData(SocketMessage message);
private void PingSendEcho(SocketMessage message) { try { this.SendData("echo", message.Member, message.Data, message.FromID); } catch (Exception ex) { this.Log(ex); } }
private void ProcessIncomingBuffer(ref string bufferIn) { string packetIn = ExtractPacket(ref bufferIn); if (String.IsNullOrEmpty(packetIn)) return; using (var sr = new StringReader(packetIn)) { using (var reader = new XML.Reader(sr)) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "SocketMessage": this.packetsIn++; var message = new SocketMessage(reader); if (!this.ProcessMessage(message) && this.IsHost) { this.parent.ProcessMessage(this, message); } break; default: break; } } } } } }
private void PingReciveEcho(SocketMessage message) { try { if (pingStopWatch == null) return; long pingTime = long.Parse(message.Data); int pingID = int.Parse(message.Member); long pingDuration = this.pingStopWatch.ElapsedMilliseconds - pingTime; if (pingID == this.lastPingID) { this.Store("Me.Ping", pingDuration.ToString()); } } catch (Exception ex) { this.Log(ex); } }
public override void SendData(SocketMessage message) { try { lock (messagesOut) { messagesOut.Add(message); } } catch (Exception ex) { this.Log(ex); } }
private void UpdateHistory(string direction, SocketMessage message) { this.Invoke((MethodInvoker) delegate { this.UpdateControls(); this.MessageList.BeginUpdate(); ListViewItem newItem = new ListViewItem(message.Id.ToString()); newItem.SubItems.Add(direction); newItem.SubItems.Add(message.FromID.ToString()); newItem.SubItems.Add(message.ToID.ToString()); newItem.SubItems.Add(message.Command); this.MessageList.Items.Add(newItem); int max = (this.MessageList.ClientSize.Height / this.MessageList.GetItemRect(0).Height) - 1; while (this.MessageList.Items.Count > max) { this.MessageList.Items.RemoveAt(0); } this.MessageList.Columns[0].Width = -2; this.MessageList.Columns[1].Width = -2; this.MessageList.Columns[2].Width = -2; this.MessageList.Columns[3].Width = -2; this.MessageList.Columns[4].Width = -2; this.MessageList.EndUpdate(); }); }