private void AddingComputers_Load(object sender, EventArgs e) { try { setStats(); compDetails = db.GetKnownClients(); foreach (string[] details in compDetails) { KnownClient c = new KnownClient(details[0], details[1], details[2], details[3], details[4], details[5]); offlineClients.Add(c); } } catch (System.Exception ex) { MessageBox.Show(ex.Message); } this.objectListOffline.SetObjects(offlineClients); this.objectListOffline.PrimarySortColumn = null; //Form loads, starts sending off multicasts pew pew pew this.objectListView1.SetObjects(clients); constAddClient = new Thread(AddClients); constAddClient.Start(); this.groupName.GroupKeyGetter = delegate(object rowObject) { ClientThread client = (ClientThread)rowObject; return client.GetGroupName(); }; this.groupName.GroupKeyToTitleConverter = delegate(object groupKey) { return ((string)groupKey).ToString(); }; this.objectListView1.PrimarySortColumn = this.groupName; //Client hits the multicasts, responds with IP address. //Server adds this client to its lists of clients //Sends command to client, asking for name and whatnot of hardware. }
void CheckHeartBeat(TcpClient heartbeat, ClientThread c) { Messaging.SendCommand("return GetCompDB()", c.GetClientSocket()); string[] compDB = Messaging.RecieveComputerDetails(c.GetClientSocket()); KnownClient kc = new KnownClient(compDB[0], compDB[2], compDB[1], "N/A", "N/A", compDB[3]); bool connected = true; do { try { if (heartbeat.Client.Poll(0, SelectMode.SelectRead)) { byte[] buff = new byte[1]; if (heartbeat.Client.Receive(buff, SocketFlags.Peek) == 0) { MessageBox.Show("Client left :: "); connected = false; } } } catch (Exception e) { // MessageBox.Show("Client left :: "); connected = false; objectListOffline.AddObject(kc); objectListView1.RemoveObject(c); } // if (heartbeat.GetStream().ReadByte() < 0 ) { MessageBox.Show("Gone"); } } while (connected); }
private void shutdownToolStripMenuItem_Click(object sender, EventArgs e) { foreach (Object obj in objectListView1.SelectedObjects) { ClientThread c = (ClientThread)obj; Messaging.SendCommand("return GetCompDB()", c.GetClientSocket()); string[] compDB = Messaging.RecieveComputerDetails(c.GetClientSocket()); KnownClient kc = new KnownClient(compDB[0], compDB[2], compDB[1], "N/A", "N/A", compDB[3]); objectListOffline.AddObject(kc); Messaging.SendCommand("PowerControl(5);", c.GetClientSocket()); clients.Remove((ClientThread)obj); objectListView1.RemoveObject(obj); } }