C
C#3y ago
Boop

Socket Identification Help & Sending Bitmaps

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);
}
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);
}
This is my void to send a bitmap of the screen but I do not know how to do packet identification with sending an image & how to do it with integers instead of strings
11 Replies
Buddy
Buddy3y ago
Make a packet system, you can use MessagePack for help with serialization / deserialization of packets.
Boop
BoopOP3y ago
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]);
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]);
this is what I got atm
Buddy
Buddy3y ago
As for how you can identify users, send a token with the packet that contains the identification of the user.
Boop
BoopOP3y ago
what I have is a client connects to a socket server but when they send data, I want to know what data they are sending, the purpose of it
Buddy
Buddy3y ago
header | payload length | payload That's usually the structure of packets
Boop
BoopOP3y ago
is it initial data, is it a screen yeah so when I do socket.Send where can I put an identifier to tell the server what it even is anyone?
canton7
canton73y ago
You were just told how to solve that?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
canton7
canton73y ago
(it doesn't have to be MessagePack of course -- any serialization format works. The point is being able to pack multiple bits of data into a single string / byte sequence, in a way in which you can unpack them again at the other end)
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Boop
BoopOP3y ago
no? anyone?
Want results from more Discord servers?
Add your server