public string Read() { int messageByteLength = int.Parse(stream.ReadBytes(6)); stream.ReadBytes(1); // skip the colon string message = stream.ReadBytes(messageByteLength); if (EndIdentifier.Matches(message)) { IsEnd = true; socket.Close(); return(null); } return(message); }
public string Read() { string lengthString = string.Empty; while (true) { var lengthCharacter = stream.ReadBytes(1); if (lengthCharacter == ":") { break; } lengthString += lengthCharacter; } int messageByteLength = int.Parse(lengthString); string message = stream.ReadBytes(messageByteLength); if (EndIdentifier.Matches(message)) { IsEnd = true; socket.Close(); return(null); } return(message); }
public void Close() { socket.Close(); }