1

私はLANベースのオフィス間メッセージングシステムに取り組んでいます。

私のアプリケーションの手順は次のとおりです。

  1. サーバーが起動し、クライアントをリッスンします
  2. 接続中のクライアントは、接続されている他のすべてのクライアントのビューを取得します。
  3. サーバーへの接続時に、データベースをチェックインして、そのクライアントが承認されているかどうかを確認します。
  4. サーバーへのクライアント接続でデータベースをチェックインしない場合、アプリケーションは正常に動作します。そうでない場合、データベースにクライアントが存在しない場合、クライアントアプリケーションは閉じられます。

関連するコードはここにあります:

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);
            }
        }
    }

誰かがこの悪いことを取り除くために何をすべきかを提案することができますか?

4

1 に答える 1

0

サーバーの起動時に、最初にすべての有効なユーザーについてデータベースにクエリを実行し、それらの結果をキャッシュすることを検討しましたか? これにより、すべてのユーザー接続に対してクエリを実行する必要がなくなります。資格のあるユーザーをディクショナリまたは他のスタイルのルックアップ テーブルに格納できます。

于 2012-06-16T13:18:59.450 に答える