1

I'm currently developing a remote desktop application, and I have stumbled across one major issue. Keep in mind I am using a simple TCP library that sends data to the server like so: MainClient.Send(Byte[] Data);

The problem i'm having is I need to be able to differentiate the data, like attaching a header to the data so the server knows what to do with it. The current solution I have is switching a bool on and off based on if the client is streaming the screen so the server knows what to do with the data its receiving. (While the bool is true, any data received is automatically converted to an image.)

How can I do this within a sensitive byte array that is carrying an image then have the server be able to read the header to tell what it is. (So I can carry out multiple other functions with the client at the same time)

nvoigt
  • 75,013
  • 26
  • 93
  • 142
Velvet
  • 33
  • 1
  • 1
  • 5
  • You will need to implement a basic protocol, send content metadata with the bytes, including length and if you are really careful a checksum. on the otherside, read the metadata, grab the bytes you need, and do what you need – TheGeneral Mar 11 '19 at 02:30
  • You might also try serializing it to a JSON stream, this link might help https://stackoverflow.com/questions/44370046/how-do-i-serialize-object-to-json-using-json-net-which-contains-an-image-propert – vscoder Mar 11 '19 at 02:38

1 Answers1

0

If I understand your question right, you are trying to differentiate what type of data was received.

This could be easily accomplished by adding the "header byte" to the bytes to be send, and analyse it on the server end.

List<Byte> bytesToBeSend = new List<Byte>();

bytesToBeSend.Add(0);    //Assuming 0 is the image type.
bytesToBeSend.AddRange(dataToBeSend);
MainClient.Send(bytesToBeSend.ToArray());

And when the data was received, do:

Byte[] bytesToBeProcess = bytes.Skip(1).ToArray();

switch(bytes[0])
{
    case 0:    //Image type.
        //Do whatever you want with bytesToBeProcess.
        break;
    case 1:    //Text type, for example, and so on.
        //...
        break;
    default:
        //...
        break;
}

This is just the basic idea, please change the code to fit what you need!

PiggyChu001
  • 440
  • 6
  • 20