public void Receiver()
byte Metadata_Raw = new byte;
int Metadata_Raw_Lenght = Client.Receive(Metadata_Raw);
//Exit if disconnected
if (!(Metadata_Raw_Lenght > 0))
//Convert metadata to string
string Metadata = System.Text.Encoding.UTF8.GetString(Metadata_Raw, 0, Metadata_Raw_Lenght);
//Get info from metadata
Match MetaData_Formated = rgx.Match(Metadata);
//Exit if metadata is not valid
//Get type, receive it and fire the event
int totalLenght = int.Parse(MetaData_Formated.Groups.Value);
byte tmpData = new byte[totalLenght];
int len = Client.Receive(tmpData);
if (len < totalLenght)
TCP does not use "Messages", it uses streams. So once send does not equal one receive, you could have "messages" combined together or split apart.
You need to create your own message system, which it looks like you have started with
Metadata, but you need to keep calling
Read until you have received all of the metadata and you need to be careful you have not read extra information.
See TCP Message Framing by Stephen Cleary for a deeper explanation of what is going wrong.