public void SendNextQueueItem() { if (OutgoingInstructions.Count > 0) { Debug($"Start sending message to Server: [{OutgoingInstructions[0].Key}]", DebugParams); Data = Encoding.ASCII.GetBytes(EncodeMessage(OutgoingInstructions[0].Key)); ClientSocket.Send(Data); OutgoingInstructions.RemoveAt(0); } }
public void SendNextQueueItem() { if (OutgoingInstructions.Count > 0 && SendStreamOpen) { SendStreamOpen = false; Debug($"Start sending message to {OutgoingInstructions[0].Value.GetHashCode()}: [{OutgoingInstructions[0].Key}]", DebugParams); Data = Encoding.ASCII.GetBytes(EncodeMessage(OutgoingInstructions[0].Key)); OutgoingInstructions[0].Value.BeginSend(Data, 0, Data.Length, SocketFlags.None, new AsyncCallback(OnClientSend), OutgoingInstructions[0].Value); Start(); OutgoingInstructions.RemoveAt(0); } }
/// <summary> /// Sends the next instruction from the outgoing-queue. /// </summary> protected override void AsyncInstructionSendNext() { base.AsyncInstructionSendNext(); if (!haltActive) { byte[] buffer; buffer = Encoding.UTF8.GetBytes(OutgoingInstructions[0].Encode()); LocalSocket.Send(buffer, 0, buffer.Length, SocketFlags.None); Debug($"Sent Message to {OutgoingInstructions[0].Receiver.ToString()}.", DebugType.Info); Debug(OutgoingInstructions[0].ToString(), DebugType.Info); OutgoingInstructions.RemoveAt(0); } else { Debug("Could not send message. Client is in halt-mode. Waiting for 5 seconds...", DebugType.Error); Thread.Sleep(5000); } }
private void SendNextInstruction() { if (OutgoingInstructions.Count > 0) { Socket current = OutgoingInstructions[0]?.Client?.Socket; byte[] data; if (OutgoingInstructions[0].RSAEncrypted && OutgoingInstructions[0].Client.PublicKey != null) { data = Encoding.UTF8.GetBytes(OutgoingInstructions[0].Instruction.Encode(true, OutgoingInstructions[0].Client.PublicKey)); } else { data = Encoding.UTF8.GetBytes(OutgoingInstructions[0].Instruction.Encode(false)); } current.Send(data); Debug($"Sent Message to {OutgoingInstructions[0].Client.Username}: {OutgoingInstructions[0].Instruction}.", DebugParams); OutgoingInstructions.RemoveAt(0); } }
private void SendNextInstruction() { if (OutgoingInstructions.Count > 0) { byte[] buffer; string instruction; if (OutgoingInstructions[0].RSAEncrypted && ServerPublicKey != null) { instruction = OutgoingInstructions[0].Instruction.Encode(true, ServerPublicKey); } else { instruction = OutgoingInstructions[0].Instruction.Encode(false); } buffer = Encoding.UTF8.GetBytes(instruction); ClientSocket.Send(buffer, 0, buffer.Length, SocketFlags.None); Debug($"Sent Message: {instruction}.", DebugParams); OutgoingInstructions.RemoveAt(0); } }
/// <summary> /// Sends the next instruction from the outgoing-queue. /// </summary> protected override void AsyncInstructionSendNext() { base.AsyncInstructionSendNext(); if (!haltActive) { try { if ((OutgoingInstructions[0].Receiver as NetComCData).Authenticated || OutgoingInstructions[0].GetType() != typeof(InstructionLibraryEssentials.KeyExchangeServer2Client) || OutgoingInstructions[0].GetType() != typeof(InstructionLibraryEssentials.AuthenticationServer2Client)) { Socket current = OutgoingInstructions[0]?.Receiver.LocalSocket; byte[] data; data = Encoding.UTF8.GetBytes(OutgoingInstructions[0].Encode()); try { current.Send(data); } catch (Exception) { Debug("Client disconnected > Connection lost. (101)", DebugType.Warning); current.Close(); UserGroups.Disconnect(current); ConnectedClients.Remove(current); return; } Debug($"Sent Message to {OutgoingInstructions[0].Receiver.ToString()}.", DebugType.Info); Debug(OutgoingInstructions[0].ToString(), DebugType.Info); OutgoingInstructions.RemoveAt(0); } else { Debug($"Could not send Message to {OutgoingInstructions[0].Receiver.ToString()}. Authentication not valid.", DebugType.Error); Debug($"Sending Authentication-Reminder...", DebugType.Info); // Queues a authentication-reminder Send(new InstructionLibraryEssentials.AuthenticationReminder(this, OutgoingInstructions[0].Receiver)); // moves the current instruction to the back OutgoingInstructions.Add(OutgoingInstructions[0].Clone()); OutgoingInstructions.RemoveAt(0); } } catch (Exception ex) { Debug("Halting (08)", DebugType.Warning); if (ShowExceptions) { Debug($"({ex.GetType().Name}) {ex.Message}", DebugType.Exception); } if (AutoRestartOnCrash) { HaltAllThreads(); } } } else { Debug("Could not send message. Server is in halt-mode. Waiting for 5 seconds...", DebugType.Error); Thread.Sleep(5000); } }