//Shows a MessageBox with a connection request. //Activates when the "Host" user recieves a connection void Eventaction_ConnectRequest(object sender, EventArgs e) { String ClientName = sender as String; MessageBoxResult MBResult = MessageBox.Show(ClientName + " want to chat with you. Accept?", "Connection request", MessageBoxButton.YesNo); if (MBResult == MessageBoxResult.Yes) { Console.WriteLine("Yes"); //Inits the database for the "Host" user Db = new Database(MyUsername); DataPacket packet = new DataPacket(0, " ", "Connected, start chatting!", new byte[1]); Db.AddToChatHistory(packet, MyUsername); ConvoBox.Dispatcher.BeginInvoke(new Action(delegate() { ConvoBox.Items.Add(packet.DT + " " + packet.Message); })); Eventaction_EnableButtons(null, new EventArgs()); //Sends a packet to the "Client" user that the connection has been accepted DataPacket DB = new DataPacket(2, "Accept Connection", "", new byte[1]); SocketClass.Send(DB); } else if (MBResult == MessageBoxResult.No) { Console.WriteLine("No"); Eventaction_DisableButtons(null, new EventArgs()); DataPacket packet = new DataPacket(1, "shutdown", "", new byte[1]); //Sends a packet to the "Client" user that the connection has been declined SocketClass.Send(packet); //The "Host" socket closes SocketClass.CloseSocket(); } }