110,567
社区成员
发帖
与我相关
我的任务
分享
class LineReciever
{
int linesToRecive = 20;
List<byte> unprocessed = new List<byte>();
public bool OnReceive(byte[] bytes)
{
int count = Array.IndexOf(bytes, '\n') + 1;
unprocessed.AddRange(bytes.Take(count));
bytes = bytes.Skip(count).ToArray();
if (count > 0)
{
OnLineRecieved(Encoding.UTF8.GetString(unprocessed.ToArray()));
unprocessed.Clear();
if (--linesToRecive == 0) return true;
else return OnReceive(bytes);
}
unprocessed.AddRange(bytes);
return false;
}
public void OnLineRecieved(string line)
{
MessageBox.Show(line);
}
}