SOLVE The problem was that I assumed that he immediately received all the data when I told him to read, so he exited my READ SCREENSHOT method and dumped the data packet into a packet parser, which continued to spam my console using junk> . <
Thanks.
I have another new problem, this time I canβt understand what is wrong with my data streams. I'm currently trying to transfer image files that were captured to a central network server, I have Client> Server, just fine, transferring data back and forth all day, but when I try to call the screenshot function and send it, this is where I get their problems.
Current im code using for this:
Notes DataHandler is just a wrapper for sending and receiving data, AddVar is an overloaded method that takes any variable and sends it through the stream (new DataHandler (stream))
DataHandler connected to TCP stream
ReadInt and ReadLong etc. are inverse helper functions that make code management easier.
At this point, the server sends ping every second to the client, the client is configured to respond to this ping if it is not busy, responding to another packet (incoming packets are launched in one thread)
The server follows the same rule per client
Writing data to a stream in SI.TakeScreenShotAndStream, this method takes a screenshot of the client computer and transfers the data to any transmitted stream, in this case a storage stream.
end note
(client side)
try { DataHandler.AddVariable((byte)50); memoryStream = new MemoryStream(); SI.TakeScreenShotAndStream(memoryStream, quality); DataHandler.AddVariable(memoryStream.Length); memoryStream.Position = 0; memoryStream.CopyTo(clientStream); clientStream.Flush(); } catch (Exception e) { Console.WriteLine(e.Message); Disconnect(); }
and server side
if (!Directory.Exists(LoadedSettings.Directory + name)) Directory.CreateDirectory(LoadedSettings.Directory + name); fileStream = File.Create(FullPath); long length = DataHandler.ReadLong(); byte[] data = new byte[length]; clientStream.Read(data, 0, (int)length); fileStream.Write(data, 0, (int)length); fileStream.Flush(); fileStream.Close();
The function "Take a picture and save" works, I can transfer it to a FileStream and save it directly to a file, my problem is that I do not know how to work with the MemoryStream class, if I am really away from the sign about how it is to do, a useful tutorial for memory streams will be useful.
At some point, I tried to convert a MemoryStream to an array of bytes, but that didn't work either.
Just like a note, this is not just a mess, both of them are encapsulated in try / catch statements and invalid packages (all except 1, 2 and 50 atm), both exceptions and package numbers that are invalid are logged into the console when I run this code, it spews out the console so that it constantly beeps until I turn it off (there is no console.beep code in my program)
Any help would be appreciated :)