/// <summary> /// Remove client from client collection. /// </summary> /// <param name="client">Client to remove.</param> public static void RemoveClient(Client client) { if (Program.clients.Remove(client)) { client.Dispose(); } }
/// <summary> /// Add a new client to the collection. /// </summary> /// <param name="entry">Client to add.</param> public void Add(Client entry) { lock (this.thisLock) { this.innerCollection.Add(entry); this.isFull = this.innerCollection.Count >= this.capacity; } }
private static void AddClient(object context) { if (!Program.clients.IsFull) { var client = new Client(Program.address); Program.clients.Add(client); client.Communicate(); } }
/// <summary> /// Removes a client from the collection. /// </summary> /// <param name="entry">Client to remove.</param> /// <returns>true if client was removed; false otherwise.</returns> public bool Remove(Client entry) { lock (this.thisLock) { var result = this.innerCollection.Remove(entry); this.isFull = this.innerCollection.Count >= this.capacity; return result; } }
/// <summary> /// Creates the steady state message. /// </summary> /// <param name="instance">Client object.</param> /// <returns>Byte array.</returns> private static byte[] CreateSteadyStateMessage(Client instance) { var command = instance.ClientMessageProvider(); var msg = Encoding.UTF8.GetBytes(string.Format(CultureInfo.InvariantCulture, "\"{0}\"", command)); var message = new byte[msg.Length + 2]; message[0] = 0x00; Buffer.BlockCopy(msg, 0, message, 1, msg.Length); message[msg.Length + 1] = 0xFF; return message; }
private static byte[] CreateSteadyStateMessage(Client instance, string greeting) { byte[] message = null; if (instance.steadyCounter++ % 2 == 0) { var msg = Encoding.UTF8.GetBytes(string.Format(CultureInfo.InvariantCulture, "\"{0} {1:D3}{2}\"", greeting, instance.id, instance.GetLastMessageRead())); message = new byte[msg.Length + 2]; message[0] = 0x84; message[1] = (byte)(msg.Length & 0x7F); Buffer.BlockCopy(msg, 0, message, 2, msg.Length); } else { var msg = Encoding.UTF8.GetBytes(string.Format(CultureInfo.InvariantCulture, "\"{0}\"", Client.longGreeting)); message = new byte[msg.Length + 4]; message[0] = 0x84; message[1] = 126; message[2] = (byte)((msg.Length & 0xFF00) >> 8); message[3] = (byte)(msg.Length & 0x00FF); Buffer.BlockCopy(msg, 0, message, 4, msg.Length); } return message; }