title: What is the proper way to use WebSocketClient ReceiveAsync and buffer?
body: <p>I want to create a Bot class in C# for <a href="https://api.slack.com/" rel="nofollow">slack</a> to let services create and consume messages for our company.  To make it easy for our services to use, I have it just called with <code>Connect()</code> and use an event to let the caller know when there's a message.  This is basically how it will be called:</p>
  
  <pre><code>SlackBot bot = new SlackBot(TOKEN);
  bot.OnReceiveMessage += message =&gt; {
      Console.WriteLine("DELEGATE GOT MESSAGE: '{0}'", message);
  };
  bot.Connect();
  </code></pre>
  
  <p>The <code>Connect()</code> method calls an internal <code>Receive()</code> method that calls itself after every message:</p>
  
  <pre><code>public delegate void MessageReceivedDelegate(string message);
  
  public event MessageReceivedDelegate OnReceiveMessage;
  
  void Receive()
  {
      _ReceiveTask = _Client.ReceiveAsync(_ClientBuffer, _CancellationToken);
      _ReceiveTask.ContinueWith(twsrr =&gt;
      {
          WebSocketReceiveResult result = twsrr.Result;
          string message = Encoding.ASCII.GetString(_ClientBuffer.Array,
               _ClientBuffer.Offset, result.Count);
          OnReceiveMessage(message);
          Receive();
      });
  }
  </code></pre>
  
  <p>So the largest buffer acceptable is 64k, do I need to check <code>result.EndOfMessage</code> and use a MemoryStream or something to to keep adding bytes to until I get the end of the message, then send it?  </p>