title: Client disconnected on receiving message from other client
body: <p>I am working on Lan based interoffice messaging system.</p>
  
  <p>The steps in my applications are :</p>
  
  <ol>
  <li>Server starts and listen for clients</li>
  <li>Clients on connection gets the view of all the other connected clients.</li>
  <li>On connection to the server i do check in the database that if that client is authorize or not.</li>
  <li>if i dont check in the database on client connection to the server then the application does work normally other wise the client if not exists in the database the  the client application got closed.</li>
  </ol>
  
  <p>the related code is here :</p>
  
  <pre><code>public void CheckUserName(string userName)
          {
  
          if (userName != "Usman")  // checking in database( a static name)
          {
                //Check if the username is registered
                Send("sorry@Invalid Username, try another Username!!");
                Disconnect();
                return;
          }
          else
          {
              //If name is not duplicate then the client is connected
              this.connected =true;
              this.userName =userName;
              //Build the Usernames list and send it to the client
              StringBuilder userList = new StringBuilder();
              userList.Append(this.clientID);
              Hashtable clientTable =ClientList.GetList;
              foreach(DictionaryEntry d in clientTable)
              {
                  //Seperate the usernames by a '@'
                  userList.Append("@");
                  userList.Append(d.Value.ToString());
              }
              //Start the llistening
              lock(myClient.GetStream())
              {
                  AsyncCallback GetStreamMsgCallback = new AsyncCallback(GetStreamMsg);
                  myClient.GetStream().BeginRead(recByte,0,1024,GetStreamMsgCallback,null);
              }
              //Send the Userlist
              Send(userList.ToString());
              //Raise the Connected Event
              if(Connected!=null)
              {
                  EventArgs e = new EventArgs();
                  Connected(this, e);
              }
          }
      }
  </code></pre>
  
  <p>Do anyone could suggest that what to do to get rid of this bad thing?</p>