Global Text Chat Room Application using C#.Net Programming – Remoting technology 4/6
Join to ChatRoom:
Next coming the client, how client connect to server and user login to the chat room. To joining to chat room the below codes are executes
private void JoinToChatRoom()
if (chan == null && txtName.Text.Trim().Length != 0)
chan = new TcpChannel();
// Create an instance of the remote object
objChatWin = new frmChatWin();
objChatWin.remoteObj = (SampleObject)Activator.GetObject(typeof(RemoteBase.SampleObject), txtServerAdd.Text);
MessageBox.Show(txtName.Text+ ” already joined, please try with different name”);
chan = null;
objChatWin.key = objChatWin.remoteObj.CurrentKeyNo();
Here from user client application takes a name and check to server is the name available or not. If name is available then user gets the ‘CurrentKeyNo’ of server, it is the number of last chat message (how the key generated, describe in later) and open the ChatRoom window.
If user name is already taken by other user, then application asks to user for different name.
In server side to join a user in chat server “JoinToChatRoom()” method invokes, lets see what happens within the method –
public bool JoinToChatRoom(string name)
if (alOnlineUser.IndexOf(name) > –1)
SendMsgToSvr(name + ” has joined into chat room.”);
Here is user can successfully logged in to server then his name is added in a user collection, ‘alOnlineUser’ is it an ArrayList type object.
Read Next à
Read Next à