diff --git a/Server/Client.cs b/Server/Client.cs index 5e385be..78abf58 100644 --- a/Server/Client.cs +++ b/Server/Client.cs @@ -123,7 +123,6 @@ namespace Server Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}"); break; } - Array.Copy(message, 5, payloadbytes, 0, message.Length - 5); dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(payloadbytes)); saveData.WriteDataJSON(Encoding.ASCII.GetString(payloadbytes)); @@ -131,7 +130,7 @@ namespace Server else if (DataParser.isRawData(message)) { Console.WriteLine(BitConverter.ToString(message)); - saveData.WriteDataRAW(ByteArrayToString(message)); + saveData.WriteDataRAW(message); } diff --git a/Server/SaveData.cs b/Server/SaveData.cs index 0286bde..ffaaf90 100644 --- a/Server/SaveData.cs +++ b/Server/SaveData.cs @@ -22,20 +22,33 @@ namespace Server /// /// Every line is a new data entry /// - + public void WriteDataJSON(string data) { - using (StreamWriter sw = File.AppendText(this.path + "/json"+filename+".txt")) + using (StreamWriter sw = File.AppendText(this.path + "/json" + filename + ".txt")) { sw.WriteLine(data); } } - public void WriteDataRAW(string data) + public void WriteDataRAW(byte[] data) { - using (StreamWriter sw = File.AppendText(this.path + "/raw" + filename + ".txt")) + int length = 0; + try { - sw.WriteLine(data); + FileInfo fi = new FileInfo(this.path + "/raw" + filename + ".bin"); + length = (int)fi.Length; + } + catch + { + + } + using (BinaryWriter sw = new BinaryWriter(File.Open(this.path + "/raw" + filename + ".bin", FileMode.Create))) + { + + Console.WriteLine("head position " + sw.Seek(length, SeekOrigin.End)); + sw.Write(data); + sw.Flush(); } } }