Пример #1
0
        //==========================================================================================================================================================

        //====================================BTNEnvoi====================================================
        private void btnEnvoi_Click(object sender, EventArgs e)
        {
            if (!btnSart.Visible && tbxMessageEnvoit.Text != "")
            {
                if (_bEtatDestinataire == false)
                {
                    KNotification.Show(
                        "Your recipient is not active.\r\nThe discussions are not saved.\r\n Please wait for it to connect.");
                }
                else
                {
                    EnvoiDuMessage(tbxMessageEnvoit.Text, KMessage.Type.Message());
                }
            }
        }
Пример #2
0
 //======================================FIN========================FIN===============================================================================
 private void tbxMessageEnvoit_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter)
     {
         e.SuppressKeyPress = true;
         if (btnSart.Visible != true)
         {
             if (tbxMessageEnvoit.Text != "")
             {
                 if (_bEtatDestinataire == false)
                 {
                     KNotification.Show("Your recipient is not active.\r\nThe discussions are not saved.\r\n Please wait for it to connect.");
                 }
                 else
                 {
                     EnvoiDuMessage(tbxMessageEnvoit.Text, KMessage.Type.Message());
                 }
             }
         }
     }
 }
Пример #3
0
        /// <summary>
        /// The code for the method (Recipient connected/Disconnected) is integrated directly into the message sending function.
        /// It is likely to evolve and change place.
        /// The keys are used in this case as a means of comparison.
        /// </summary>
        /// <param name="aResult">Type IAsyncResult</param>
        private void MessageReceived(IAsyncResult aResult)
        {
            try
            {
                var size = _sck.EndReceiveFrom(aResult, ref _epRemote);
                if (size > 0)
                {
                    var receivedData = new byte[1464];

                    receivedData = (byte[])aResult.AsyncState;

                    var enc      = new UTF8Encoding();
                    var kMessage = new KMessage(enc.GetString(receivedData));
                    //Comparaison chaine de caractère reçu
                    if (kMessage.GetMessageType() == KMessage.Type.Init().ToString())
                    {
                        switch (kMessage.GetMessageContent())
                        {
                        case "789ZCFZTiniwjZTUvjkas79012798":
                            FrmMain.CheckForIllegalCrossThreadCalls = false;
                            _bEtatDestinataire = false;
                            RecipientStatus(_bEtatDestinataire);
                            FrmMain.CheckForIllegalCrossThreadCalls = true;
                            break;

                        case "tuiFZCz56786casdcssdcvuivgboRTSDetre67Rz7463178":
                            if (!_bEtatDestinataire)
                            {
                                FrmMain.CheckForIllegalCrossThreadCalls = false;
                                _bEtatDestinataire = true;
                                RecipientStatus(_bEtatDestinataire);
                                FrmMain.CheckForIllegalCrossThreadCalls = true;
                            }
                            break;

                        default:
                            Console.WriteLine("Default case");
                            break;
                        }
                    }
                    else
                    {
                        FrmMain.CheckForIllegalCrossThreadCalls = false;
                        lbxTchat.Items.Add("Him :      " + kMessage.GetMessageContent());
                        FrmMain.CheckForIllegalCrossThreadCalls = true;
                        if (_bNotificationsEnable)
                        {
                            KNotification.Show(kMessage.GetMessageContent());
                        }
                    }
                }

                var buffer = new byte[1500];
                _sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref _epRemote, new AsyncCallback(MessageReceived), buffer);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());
                Application.Exit();
            }
        }