So I have a Socket with C# (.NET Framework) and I want to send data to the server from the client however I do not know how to identify what it is to the server. I initially used strings at the beginning of the packet but when sending something like a Bitmap to the server, it didn't work out for me. Someone suggested using integers and what not but I do not know how to do that.
My Client Reading Data
private static void SendScreen()
{
MemoryStream ms = new MemoryStream();
ms.Write(Encoding.ASCII.GetBytes("screen:"), 0, Encoding.ASCII.GetBytes("EOF").Length);
Helpers.GetScreen().Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
var imageData = ms.ToArray();
var lengthData = BitConverter.GetBytes(imageData.Length);
ClientSocket.Send(imageData, 0, imageData.Length, SocketFlags.None);
}
My Server Data Reader
byte[] recBuf = new byte[received];
Array.Copy(buffer, recBuf, received);
string text = Encoding.ASCII.GetString(recBuf);
Console.WriteLine("Received Text: " + text);
string[] brokenText = text.Split(":".ToCharArray());
Console.WriteLine("EventName: " + brokenText[0]);