/// <summary> /// Sends an instruction to the server. It's in a lock (using monitor lock) to prevent multiple sending instructions at the same time. /// </summary> /// <param name="command">The type of instruction to send.</param> /// <param name="arg1">An argument to pass along with the instruction.</param> /// <param name="arg2">An argument to pass along with the instruction.</param> /// <param name="arg3">An argument to pass along with the instruction.</param> /// <param name="arg4">An argument to pass along with the instruction.</param> public void SendInstruction(Instruction.Type command, string arg1 = "", string arg2 = "", string arg3 = "", string arg4 = "") { lock (sendLock) { try { Instruction newInstruction = new Instruction() { Command = command, Arg1 = arg1, Arg2 = arg2, Arg3 = arg3, Arg4 = arg4 }; // Send instruction byte[] dataToSend = Serializer.Serialize(newInstruction); socket.Send(dataToSend, dataToSend.Length); } catch (Exception ex) { } } }
/// <summary> /// Converts Instruction to byte[]. /// </summary> /// <param name="obj">The Instruction to be serialized.</param> /// <returns>A byte array of the Instruction.</returns> public static byte[] Serialize(Instruction obj) { return System.Text.Encoding.Default.GetBytes( Pathfinding.Serialization.JsonFx.JsonWriter.Serialize(obj) ); }