// (4) Send The Recieved Data to All Clients in The Room public static void OnRecievedData(IAsyncResult ar) { TClient client = (TClient)ar.AsyncState; byte[] aryRet = client.GetRecievedData(ar); if (aryRet.Length < 1) { client.ReadSocket.Close(); ClientsList.Remove(client); return; } else { Message msg = new Message(aryRet); if (msg.enumCommand == Command.Join) { if (msg.strRoom != null) { client.room = msg.strRoom; client.uname = msg.strName; Message userjoined = new Message(); userjoined.strName = msg.strName; userjoined.enumCommand = Command.Join; userjoined.strRoom = msg.strRoom; userjoined.strMessage = msg.strName + " has joined " + msg.strRoom; parent.Invoke(parent.multicast_msg_2room, userjoined); //notify all room users for new joining parent.Invoke(parent.sendroomlistdelobj, msg.strRoom); //send list of users to the newly joined usr //parent.Invoke(parent.usersynobj, client); } else { client.uname = msg.strName; //Message selroom = new Message(); //selroom.enumCommand = Command.Msg; //selroom.strMessage = "Connected.Please Select Room."; //selroom.strName = "Server"; //client.ReadSocket.Send(selroom.ToByte()); } } else if (msg.enumCommand == Command.Msg) { parent.Invoke(parent.multicast_msg_2room, msg); } else if (msg.enumCommand == Command.Draw) { parent.Invoke(parent.multicast_msg_2room, msg); } else if (msg.enumCommand == Command.Left) { if (client.room != null) { Message userleft = new Message(); userleft.enumCommand = Command.Left; userleft.strMessage = client.uname + " has left " + client.room; userleft.strRoom = client.room; parent.Invoke(parent.multicast_msg_2room, userleft); } string temproom = client.room; client.room = msg.strRoom; if (temproom != null) { parent.Invoke(parent.sendroomlistdelobj, temproom); } parent.Invoke(parent.sendroomlistdelobj, client.room); Message userjoin = new Message(); userjoin.enumCommand = Command.Join; userjoin.strMessage = client.uname + " has joined " + client.room; userjoin.strRoom = msg.strRoom; parent.Invoke(parent.multicast_msg_2room, userjoin); Message clearCmd = new Message(); clearCmd.enumCommand = Command.Draw; clearCmd.strMessage = Command.Clear.ToString() + "?"; clearCmd.strName = client.uname; client.ReadSocket.Send(clearCmd.ToByte()); } client.SetupRecieveCallback(); } }