私はLANベースのオフィス間メッセージングシステムに取り組んでいます。
私のアプリケーションの手順は次のとおりです。
- サーバーが起動し、クライアントをリッスンします
- 接続中のクライアントは、接続されている他のすべてのクライアントのビューを取得します。
- サーバーへの接続時に、データベースをチェックインして、そのクライアントが承認されているかどうかを確認します。
- サーバーへのクライアント接続でデータベースをチェックインしない場合、アプリケーションは正常に動作します。そうでない場合、データベースにクライアントが存在しない場合、クライアントアプリケーションは閉じられます。
関連するコードはここにあります:
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);
}
}
}
誰かがこの悪いことを取り除くために何をすべきかを提案することができますか?