Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello guys if i send packet with image bytes to server i need to get the only image bytes to convert back to image ...

Client side :
C#
public class Image : Writer, Interfaces.IPacket
{
public byte[] Buffer;
public byte[] ImageBytes;

public Image()
{
}

public void Deserialize(byte[] buffer)
{
Buffer = buffer;
}

public byte[] ToArray()
{
Buffer = new byte[(ImageBytes) + 6];
Writer.WriteUInt16(1003, 0 Buffer);
Writer.WriteUint16((ushort)(Buffer.Length), 2, Buffer);
Writer.WriteBytes(ImageBytes, 4, Buffer);
return Buffer;
}
}


and writeBytes :

C#
public static void WriteBytes(byte[] arg, int offset, byte[] buffer)
    {
        foreach (byte arg2 in arg)
        {
            if (buffer == null)
                return;
            if (offset > buffer.Length - 1)
                return;
            buffer[offset++] = arg2;
        }
    } 

Server Side :

C#
ushort PacketID = BitConverter.UInt16(packet, 0);
ushort Length = BitConverter.UInt16(packet, 2);


so i can get packet id and length from packet ... but how to get image bytes ?
Posted
Updated 15-Jan-15 8:38am
v2
Comments
Sergey Alexandrovich Kryukov 15-Jan-15 14:57pm    
Why sending and receiving only the "image bytes"? You could send the whole image file, with all its compression, metadata, to be sure that on the other end it could be deserialized accurately? Why doing anything else?
—SA
Ali Al-Masry 15-Jan-15 15:13pm    
how to do that ?
Sergey Alexandrovich Kryukov 15-Jan-15 15:33pm    
To do what? Image files can be written to stream and read from stream. It does not matter if the stream is file, network or any other.
—SA
Ali Al-Masry 15-Jan-15 15:37pm    
any sample ?

i made this cuz i want to know which coming packet and its length ...

Sergey Alexandrovich Kryukov 15-Jan-15 16:02pm    
I put my answer, please see. The MSDN help pages usually have code samples. But why? Just read it and act by definition, ask further questions only if you face some problems.
—SA

 
Share this answer
 
Comments
Ali Al-Masry 15-Jan-15 17:06pm    
i used this method to get image bytes to send it as a packet i can get it's id and length in server packet handler ...
Sergey Alexandrovich Kryukov 15-Jan-15 17:09pm    
And what's the problem then? And package is something different...
—SA
Ali Al-Masry 15-Jan-15 17:24pm    
can you post a simple code i learn from it ?
Sergey Alexandrovich Kryukov 15-Jan-15 17:56pm    
Sorry, I have better things to do.
You learn a lot more if you write.
—SA
Look up WebClient.DownloadFile
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900