title: How to receive datastream until Enter key is pressed in TCP?
body: <p>I'm making a TCP chatroom where multiple clients can connect to a TCP server. I'm able to relay the messages that I send to all the clients, but unfortunately it's sending every single letter as it is typed and that is messing up the format. The behavior I want is to send the message only when the "Enter" key is pressed.</p>
  
  <p>Another problem I'm having is that when I ask for the username, it only reads in the first character of the string I type as the username. I tried debugging it, but couldn't figure out the issue. Below are my methods for sending data and receiving data.</p>
  
  <pre><code>    public void ReadData(object socket)
      {
          Socket s = (Socket)socket;
  
          byte[] buffer = new byte[1024];
          int k = 0;
          while (true)
          {               
              k = s.Receive(buffer);
              // event that triggers the Message() method
              SendGlobalMessage(s, buffer.GetString(k));  
          }
      }
  
      public void Message(Socket s, string msg)
      {
          string newMsg = String.Format("[{0}: {1}]", Connections[s], msg);
          foreach (Socket st in Connections.Keys)
          {
              st.Send(newMsg.ToByteArray());
          }
      }
  </code></pre>
  
  <p>Please show me examples of what I could do differently so I can grasp a firm idea of what to change. Thank you.</p>