I am using a socket client to send data to a socketServer :
At socket Client :
string strUser = "[Photo][User] + "\n" ; where \n is LF (Line feed) is the seperator
byte[] Ar_user = Encoding.UTF8.GetBytes(strUser)
byte[] Ar_TTL = Ar_user + PhotoByte[] ( where PhotoByte[] is the actual photo)
using this method to combine array :
byte[] rv = new byte[ a1.Length + a2.Length + a3.Length ];
System.Buffer.BlockCopy( a1, 0, rv, 0, a1.Length );
System.Buffer.BlockCopy( a2, 0, rv, a1.Length, a2.Length );
System.Buffer.BlockCopy( a3, 0, rv, a1.Length + a2.Length, a3.Length );
suppose the Ar_TTL is sent by a Socket client to a socket Server.
At socket server, the problem I want to solve:
1) Is above combine array workable ?
2) can I use this (\n) line feed inside this Ar_TTL ? will there be any of this in PhotoByte[]? what will be the best separator to use?
3) How to parse to get the [Photo][User] and the actual PhotoByte[] from Ar_TTL ? or is there other way to do parsing?
This is what I used and not sure it is workable :
data = new byte[_client.ReceiveBufferSize];
_client.GetStream().BeginRead(data, 0, System.Convert.ToInt32 (_client.ReceiveBufferSize), ReceiveMessage, null);
public void ReceiveMessage(IAsyncResult ar)
{
int bytesRead;
const int LF = 10;
int i = 0;
int start = 0;
byte[] receivePhoto;
while (data[i] != 0)
{
if (i + 1 > bytesRead)
{
break;
}
if (data[i] == LF)
{
//- How to parse and get the photoByte[] ?
}
}
}
Thanks