/*
         * Commands are received asynchronously. OnReceive is the handler for them.
         */
        private void UDP_OnReceive(IAsyncResult ar)
        {
            try {
                EndPoint receivedFromEP = new IPEndPoint(IPAddress.Any, 0);

                //Get the IP from where we got a message.
                clientSocket.EndReceiveFrom(ar, ref receivedFromEP);

                //Convert the bytes received into an object of type Data.
                Data msgReceived = new Data(byteData);


                vocoder      = msgReceived.vocoder;
                otherPartyEP = receivedFromEP;
                otherPartyIP = (IPEndPoint)receivedFromEP;
                UDP_InitializeCall();


                byteData = new byte[1024];

                //Get ready to receive more commands.
                clientSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref receivedFromEP, new AsyncCallback(UDP_OnReceive), null);
            } catch (Exception ex) {
                UDP_UninitializeCall();
                MessageBox.Show(ex.Message, "VoiceChat-OnReceive ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #2
0
        private void Call()
        {
            try
            {
                //Get the IP we want to call.
                otherPartyIP = new IPEndPoint(IPAddress.Parse(txtCallToIP.Text), 1450);
                otherPartyEP = (EndPoint)otherPartyIP;

                //Get the vocoder to be used.
                if (cmbCodecs.SelectedText == "A-Law")
                {
                    vocoder = Vocoder.ALaw;
                }
                else if (cmbCodecs.SelectedText == "u-Law")
                {
                    vocoder = Vocoder.uLaw;
                }
                else if (cmbCodecs.SelectedText == "None")
                {
                    vocoder = Vocoder.None;
                }

                //Send an invite message.
                SendMessage(Command.Invite, otherPartyEP);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "VoiceChat-Call ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #3
0
        public void AcceptCall(EndPoint receivedFromEP)
        {
            string msgTmp = (char)5 + " <EOF>";

            SendMessage(msgTmp, receivedFromEP);
            vocoder      = Vocoder.None;//msgReceived.vocoder;
            otherPartyEP = receivedFromEP;
            otherPartyIP = (IPEndPoint)receivedFromEP;
            InitializeCall();
        }
Beispiel #4
0
        private void cmbCodecs_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbCodecs.SelectedIndex == 1)
            {
                vocoder = Vocoder.ALaw;
                LogAppend("Se ha modificado codificación a: ALaw");

                if (eMode == Mode.Server)
                {
                    lock (otherPartyIPs)
                    {
                        for (int i = 0; i < otherPartyIPs.Count; i++)
                        {
                            SendMessage(Command.ChangeVocoderALaw, otherPartyIPs[i]);
                        }
                    }
                }
            }
            else if (cmbCodecs.SelectedIndex == 1)
            {
                vocoder = Vocoder.uLaw;
                LogAppend("Se ha modificado codificación a: uLaw");

                if (eMode == Mode.Server)
                {
                    lock (otherPartyIPs)
                    {
                        for (int i = 0; i < otherPartyIPs.Count; i++)
                        {
                            SendMessage(Command.ChangeVocoderuLaw, otherPartyIPs[i]);
                        }
                    }
                }
            }
            else
            {
                vocoder = Vocoder.None;
                LogAppend("Se ha modificado codificación a: None");
                if (eMode == Mode.Server)
                {
                    lock (otherPartyIPs)
                    {
                        for (int i = 0; i < otherPartyIPs.Count; i++)
                        {
                            SendMessage(Command.ChangeVocoderNone, otherPartyIPs[i]);
                        }
                    }
                }
            }
        }
Beispiel #5
0
        public void ChangeCodification(cChatEngine.Vocoder codification)
        {
            if (codification == cChatEngine.Vocoder.ALaw)
            {
                vocoder = cChatEngine.Vocoder.ALaw;
                cGlobalVars.AddLogChat("Se ha modificado codificación a: ALaw");
                if (eMode == cChatEngine.Mode.Server)
                {
                    lock (clientIPs)
                    {
                        for (int i = 0; i < clientIPs.Count; i++)
                        {
                            SendMessage(cChatEngine.Command.ChangeVocoderALaw, clientIPs[i]);
                        }
                    }
                }
            }
            else if (codification == cChatEngine.Vocoder.uLaw)
            {
                vocoder = Vocoder.uLaw;
                cGlobalVars.AddLogChat("Se ha modificado codificación a: uLaw");

                if (eMode == cChatEngine.Mode.Server)
                {
                    lock (clientIPs)
                    {
                        for (int i = 0; i < clientIPs.Count; i++)
                        {
                            SendMessage(cChatEngine.Command.ChangeVocoderuLaw, clientIPs[i]);
                        }
                    }
                }
            }
            else
            {
                vocoder = cChatEngine.Vocoder.None;
                cGlobalVars.AddLogChat("Se ha modificado codificación a: None");
                if (eMode == cChatEngine.Mode.Server)
                {
                    lock (clientIPs)
                    {
                        for (int i = 0; i < clientIPs.Count; i++)
                        {
                            SendMessage(cChatEngine.Command.ChangeVocoderNone, clientIPs[i]);
                        }
                    }
                }
            }
        }
Beispiel #6
0
 private void Call()
 {
     try
     {
         //Get the IP we want to call.
         otherPartyIP = new IPEndPoint(IPAddress.Parse(textBox3.Text), 1450);
         otherPartyEP = (EndPoint)otherPartyIP;
         vocoder      = Vocoder.ALaw;
         //Send an invite message.
         SendMessage(Command.Invite, otherPartyEP);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "VoiceChat-Call ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Beispiel #7
0
        public void Call()
        {
            try
            {
                //Get the IP we want to call.
                //otherPartyIP = new IPEndPoint(IPAddress.Parse(txtCallToIP.Text), 1450);
                string ipAddress = Program.secConv.listView1.SelectedItems[0].SubItems[1].Text.ToString();
                otherPartyIP = new IPEndPoint(IPAddress.Parse(ipAddress), 14450);
                otherPartyEP = (EndPoint)otherPartyIP;

                //Get the vocoder to be used.

                /* if (cmbCodecs.SelectedText == "A-Law")
                 * {
                 *   vocoder = Vocoder.ALaw;
                 * }
                 * else if (cmbCodecs.SelectedText == "u-Law")
                 * {
                 *   vocoder = Vocoder.uLaw;
                 * }
                 * else if (cmbCodecs.SelectedText == "None")*/
                {
                    vocoder = Vocoder.None;
                }

                //Send an invite message.
                char   comm    = (char)10;
                string message = comm + " " + Program.userLogin + " " + vocoder + " <EOF>";

                SendMessage(message, otherPartyEP);
                player        = new System.Media.SoundPlayer();
                player.Stream = Properties.Resources.Wait;
                player.PlayLooping();

                //if (callOut.ShowDialog(Program.secConv) == DialogResult.No)
                //{
                //    message = (char)6 + " <EOF>"; //FAIL
                //    SendMessage(message, otherPartyEP);
                //}
            }
            catch (Exception)
            {
                MessageBox.Show("Wystąpił problem z nawiązaniem połączenia!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #8
0
        private void UDP_Call()
        {
            try {
                this.Invoke(new MethodInvoker(() => {
                    btnVoiceChat.Text      = "Stop Voice Chat";
                    btnVoiceChat.ForeColor = Color.Red;
                }));

                //Get the IP we want to call.
                otherPartyIP = new IPEndPoint(IPAddress.Parse(txtServerIP.Text), 6068);
                otherPartyEP = (EndPoint)otherPartyIP;

                //Get the vocoder to be used.
                vocoder = Vocoder.ALaw;

                //Send an invite message.
                UDP_SendMessage(Command.Invite, otherPartyEP);
            } catch (Exception ex) {
                MessageBox.Show(ex.Message, "VoiceChat-Call ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #9
0
        private void Call()
        {
            try
            {
                if (audioLevel.SelectedIndex == 0)
                {
                    vocoder = Vocoder.ALaw;
                }
                else if (audioLevel.SelectedIndex == 1)
                {
                    vocoder = Vocoder.uLaw;
                }
                else if (audioLevel.SelectedIndex == 2)
                {
                    vocoder = Vocoder.None;
                }

                //InitializeCall();
            }
            catch (Exception ex)
            {
            }
        }
        private void UDP_Call()
        {
            try {
                //Get the IP we want to call.
                foreach (TcpClient c in clientList)
                {
                    if (c.Connected)
                    {
                        string c_ip = ((IPEndPoint)c.Client.RemoteEndPoint).Address.ToString();

                        otherPartyIP = new IPEndPoint(IPAddress.Parse(c_ip), 1550);
                        otherPartyEP = (EndPoint)otherPartyIP;

                        //Get the vocoder to be used.
                        vocoder = Vocoder.ALaw;

                        //Send an invite message.
                        UDP_SendMessage(Command.Invite, otherPartyEP);
                    }
                }
            } catch (Exception ex) {
                MessageBox.Show(ex.Message, "VoiceChat-Call ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #11
0
        /*
         * Commands are received asynchronously. OnReceive is the handler for them.
         */
        private void OnReceive(IAsyncResult ar)
        {
            try
            {
                EndPoint receivedFromEP = new IPEndPoint(IPAddress.Any, 0);

                //Get the IP from where we got a message.
                clientSocket.EndReceiveFrom(ar, ref receivedFromEP);

                //Convert the bytes received into an object of type Data.
                Data msgReceived = new Data(byteData);

                //Act according to the received message.
                switch (msgReceived.cmdCommand)
                {
                case Command.ChangeVocoderALaw:
                    LogAppend("El servidor cambio el modo a ALaw");
                    break;

                case Command.ChangeVocoderNone:
                    LogAppend("El servidor cambio el modo a None");
                    break;

                case Command.ChangeVocoderuLaw:
                    LogAppend("El servidor cambio el modo a uLaw");
                    break;

                //We have an incoming call.
                case Command.Invite:
                {
                    if (bIsServerStarted)
                    {
                        LogAppend("Se ha conectado: " + receivedFromEP.ToString());
                        vocoder = msgReceived.vocoder;

                        lock (otherPartyIPs)
                        {
                            if (!ExistsIp((IPEndPoint)receivedFromEP))
                            {
                                otherPartyIPs.Add((IPEndPoint)receivedFromEP);
                            }
                        }

                        SendMessage(Command.OK, receivedFromEP);
                    }

                    break;
                }

                //OK is received in response to an Invite.
                case Command.OK:
                {
                    if (!bIsServerStarted)
                    {
                        eMode = Mode.Client;

                        //Solamente puede recibir este parametro si no está en modo servidor
                        lock (otherPartyIPs)
                        {
                            otherPartyIPs.Clear();
                            otherPartyIPs.Add((IPEndPoint)receivedFromEP);
                        }

                        LogAppend("Connectado a : " + receivedFromEP.ToString());

                        InitializeCall();
                    }

                    break;
                }

                //Remote party is busy.

                case Command.Bye:
                {
                    //Check if the Bye command has indeed come from the user/IP with which we have
                    //a call established. This is used to prevent other users from sending a Bye, which
                    //would otherwise end the call.
                    if (receivedFromEP.Equals(otherPartyEP) == true)
                    {
                        //End the call.
                        UninitializeCall();
                    }
                    break;
                }
                }

                byteData = new byte[1024];
                //Get ready to receive more commands.

                if (!bStop)
                {
                    clientSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref receivedFromEP, new AsyncCallback(OnReceive), null);
                }
                else
                {
                    IsThreadReceiveCommandsEnd = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "VoiceChat-OnReceive ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void Call()
        {
            try
            {
                //Get the IP we want to call.
                otherPartyIP = new IPEndPoint(IPAddress.Parse(txtCallToIP.Text), 1450);
                otherPartyEP = (EndPoint)otherPartyIP;

                //Get the vocoder to be used.
                if (cmbCodecs.SelectedText == "A-Law")
                {
                    vocoder = Vocoder.ALaw;
                }
                else if (cmbCodecs.SelectedText == "u-Law")
                {
                    vocoder = Vocoder.uLaw;
                }
                else if (cmbCodecs.SelectedText == "None")
                {
                    vocoder = Vocoder.None;
                }

                //Send an invite message.
                SendMessage(Command.Invite, otherPartyEP);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "VoiceChat-Call ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /*
         * Commands are received asynchronously. OnReceive is the handler for them.
         */
        private void OnReceive(IAsyncResult ar)
        {
            try
            {
                EndPoint receivedFromEP = new IPEndPoint(IPAddress.Any, 0);

                //Get the IP from where we got a message.
                clientSocket.EndReceiveFrom(ar, ref receivedFromEP);

                //Convert the bytes received into an object of type Data.
                Data msgReceived = new Data(byteData);

                //Act according to the received message.
                switch (msgReceived.cmdCommand)
                {
                    //We have an incoming call.
                    case Command.Invite:
                        {
                            if (bIsCallActive == false)
                            {
                                //We have no active call.

                                //Ask the user to accept the call or not.
                                if (MessageBox.Show("Call coming from " + msgReceived.strName + ".\r\n\r\nAccept it?",
                                    "VoiceChat", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                                {
                                    SendMessage(Command.OK, receivedFromEP);
                                    vocoder = msgReceived.vocoder;
                                    otherPartyEP = receivedFromEP;
                                    otherPartyIP = (IPEndPoint)receivedFromEP;
                                    InitializeCall();
                                }
                                else
                                {
                                    //The call is declined. Send a busy response.
                                    SendMessage(Command.Busy, receivedFromEP);
                                }
                            }
                            else
                            {
                                //We already have an existing call. Send a busy response.
                                SendMessage(Command.Busy, receivedFromEP);
                            }
                            break;
                        }

                    //OK is received in response to an Invite.
                    case Command.OK:
                        {
                            //Start a call.
                            InitializeCall();
                            break;
                        }

                    //Remote party is busy.
                    case Command.Busy:
                        {
                            MessageBox.Show("User busy.", "VoiceChat", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            break;
                        }

                    case Command.Bye:
                        {
                            //Check if the Bye command has indeed come from the user/IP with which we have
                            //a call established. This is used to prevent other users from sending a Bye, which
                            //would otherwise end the call.
                            if (receivedFromEP.Equals (otherPartyEP) == true)
                            {
                                //End the call.
                                UninitializeCall();
                            }
                            break;
                        }
                }

                byteData = new byte[1024];
                //Get ready to receive more commands.
                clientSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref receivedFromEP, new AsyncCallback(OnReceive), null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "VoiceChat-OnReceive ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #14
0
        private void OnReceive(IAsyncResult ar)
        {
            try
            {
                EndPoint receivedFromEP = new IPEndPoint(IPAddress.Any, 0);

                //Get the IP from where we got a message.
                clientSocket.EndReceiveFrom(ar, ref receivedFromEP);

                //Convert the bytes received into an object of type Data.
                Data msgReceived = new Data(byteData);

                //Act according to the received message.
                switch (msgReceived.cmdCommand)
                {
                //We have an incoming call.
                case Command.Invite:
                {
                    if (bIsCallActive == false)
                    {
                        //We have no active call.

                        //Ask the user to accept the call or not.
                        if (MessageBox.Show("The Call is coming from " + msgReceived.strName + ".\r\n\r\nAccept it?",
                                            "VoiceChat", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            SendMessage(Command.OK, receivedFromEP);
                            vocoder      = msgReceived.vocoder;
                            otherPartyEP = receivedFromEP;
                            otherPartyIP = (IPEndPoint)receivedFromEP;
                            InitializeCall();
                            ReadImg = new Thread(new ThreadStart(Start_Receiving_Video_Conference));
                            ReadImg.Start();
                            videocall();
                        }
                        else
                        {
                            //The call is declined. Send a busy response.
                            SendMessage(Command.Busy, receivedFromEP);
                        }
                    }
                    else
                    {
                        //We already have an existing call. Send a busy response.
                        SendMessage(Command.Busy, receivedFromEP);
                    }
                    break;
                }

                //OK is received in response to an Invite.
                case Command.OK:
                {
                    //Start a call.
                    ReadImg = new Thread(new ThreadStart(Start_Receiving_Video_Conference));
                    ReadImg.Start();
                    InitializeCall();
                    videocall();
                    // ImageTopic.Start();
                    break;
                }

                //Remote party is busy.
                case Command.Busy:
                {
                    MessageBox.Show("User busy.", "VoiceChat", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    break;
                }

                case Command.Bye:
                {
                    //Check if the Bye command has indeed come from the user/IP with which we have
                    //a call established. This is used to prevent other users from sending a Bye, which
                    //would otherwise end the call.
                    if (receivedFromEP.Equals(otherPartyEP) == true)
                    {
                        //End the call.
                        UninitializeCall();
                    }
                    break;
                }
                }

                byteData = new byte[1024];
                //Get ready to receive more commands.
                clientSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref receivedFromEP, new AsyncCallback(OnReceive), null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "VoiceChat-OnReceive ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #15
0
        private void OnReceive(IAsyncResult ar)
        {
            try
            {
                EndPoint receivedFromEP = new IPEndPoint(IPAddress.Any, 0);

                //Get the IP from where we got a message.
                LogLine("(IN) We are receiving a data...");
                clientSocket.EndReceiveFrom(ar, ref receivedFromEP);

                //Convert the bytes received into an object of type Data.
                Data msgReceived = new Data(byteData);

                string newip = ((IPEndPoint)receivedFromEP).Address.ToString();
                if (!Contacts.Items.Contains(newip))
                {
                    Contacts.Items.Add(newip);
                    string[] temp = new string[chats.Length];
                    chats.CopyTo(temp, 0);
                    chats = new string[temp.Length + 1];
                    temp.CopyTo(chats, 0);
                }

                //Act according to the received message.
                switch (msgReceived.cmdCommand)
                {
                    //We have an incoming call.
                    case Command.Invite:
                        {
                            LogLine("Incoming call...");
                            lastringed = Contacts.Items.IndexOf(newip);
                            chats[Contacts.Items.IndexOf(newip)] += DateTime.Now + " *Вам звонит " + msgReceived.strName + " *\r\n";
                            UpdateChatText();
                            tabControl1.SelectTab(1);

                            if (bIsCallActive == false)
                            {
                                //We have no active call.
                                incomingsound.PlayLooping();
                                //Ask the user to accept the call or not.
                                if (MessageBox.Show("Вам звонит " + msgReceived.strName + ".\r\n\r\nОтветить на звонок?", "Входящий вызов | Fenazy", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                                {
                                    incomingsound.Stop();
                                    othername = msgReceived.strName;
                                    SendMessage(Command.OK, receivedFromEP);
                                    vocoder = msgReceived.vocoder;
                                    otherPartyEP = receivedFromEP;
                                    otherPartyIP = (IPEndPoint)receivedFromEP;
                                    InitializeCall();
                                }
                                else
                                {
                                    incomingsound.Stop();
                                    declinedsound.Play();
                                    //The call is declined. Send a busy response.
                                    chats[Contacts.Items.IndexOf(newip)] += DateTime.Now + " *Вы отклонили вызов от " + msgReceived.strName + " *\r\n";
                                    UpdateChatText();
                                    tabControl1.SelectTab(1);
                                    SendMessage(Command.Busy, receivedFromEP);
                                }
                            }
                            else
                            {
                                //We already have an existing call. Send a busy response.
                                SendMessage(Command.Busy, receivedFromEP);
                            }
                            break;
                        }

                    //OK is received in response to an Invite.
                    case Command.OK:
                        {
                            WaitForAnswerTimer.Stop();
                            //Start a call.
                            LogLine("Initializing a call...");
                            InitializeCall();
                            break;
                        }

                    //Remote party is busy.
                    case Command.Busy:
                        {
                            WaitForAnswerTimer.Stop();
                            chats[Contacts.Items.IndexOf(newip)] += DateTime.Now + " *Абонент занят*\r\n";
                            UpdateChatText();
                            MessageBox.Show("Пользователь отклонил ваш звонок.", "Занято | Fenazy", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            break;
                        }

                    case Command.Bye:
                        {
                            //Check if the Bye command has indeed come from the user/IP with which we have
                            //a call established. This is used to prevent other users from sending a Bye, which
                            //would otherwise end the call.
                            if (receivedFromEP.Equals(otherPartyEP) == true)
                            {
                                //End the call.
                                LogLine("Ending the call...");
                                endsound.Play();
                                UninitializeCall();
                            }
                            break;
                        }
                    case Command.Chat:
                        {
                            chats[Contacts.Items.IndexOf(newip)] += DateTime.Now + " " + msgReceived.strName + ": " + msgReceived.txt + "\r\n";
                            Contacts.SelectedIndex = Contacts.Items.IndexOf(newip);
                            tabControl1.SelectTab(1);
                            break;
                        }
                }

                byteData = new byte[1024];
                //Get ready to receive more commands.
                clientSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref receivedFromEP, new AsyncCallback(OnReceive), null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка при установке вызова | Fenazy", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #16
0
        /*
        * Commands are received asynchronously. OnReceive is the handler for them.
        */
        private void OnReceive(IAsyncResult ar)
        {
            //TODO: Switch Receive Commands

            try
            {

                EndPoint receivedFromEP = new IPEndPoint(IPAddress.Any, 0);

                //Get the IP from where we got a message.
                clientSocket.EndReceiveFrom(ar, ref receivedFromEP);

                //Convert the bytes received into an object of type Data.
                Data msgReceived = new Data(byteData);

                //Act according to the received message.
                switch (msgReceived.cmdCommand)
                {

                    case Command.ChangeVocoderALaw:

                        if (IsServiceStarted && eMode == Mode.Client && receivedFromEP.Equals(serverEP))
                        {
                            cGlobalVars.AddLogChat("El servidor cambio el modo a ALaw");

                            //Cambiamos el combo box
                            SetCodecCombo(1);
                        }
                        break;
                    case Command.ChangeVocoderNone:

                        if (IsServiceStarted && eMode == Mode.Client && receivedFromEP.Equals(serverEP))
                        {
                            cGlobalVars.AddLogChat("El servidor cambio el modo a None");
                            //cmbCodecs.SelectedIndex = 0;
                            SetCodecCombo(0);
                        }
                        break;
                    case Command.ChangeVocoderuLaw:
                        if (IsServiceStarted && eMode == Mode.Client && receivedFromEP.Equals(serverEP))
                        {
                            cGlobalVars.AddLogChat("El servidor cambio el modo a uLaw");
                            SetCodecCombo(2);

                        }
                        break;

                    //MODO SERVER: recepción de invitación por parte de cliente.
                    case Command.Invite:
                        {
                            if (IsServiceStarted && eMode == Mode.Server)
                            {

                                cGlobalVars.AddLogChat("Se ha conectado: " + receivedFromEP.ToString());
                                vocoder = msgReceived.vocoder;

                                lock (clientIPs)
                                {
                                    if (!ExistsIp((IPEndPoint)receivedFromEP))
                                        clientIPs.Add((IPEndPoint)receivedFromEP);
                                }

                                SendMessage(Command.OK, receivedFromEP);

                            }

                            break;
                        }

                    //CLIENTE: Respuesta del servidor de nuestra petición de conexión
                    case Command.OK:
                        {

                            if (eMode == Mode.PreClient && receivedFromEP.Equals(serverEP))
                            {
                                eMode = Mode.Client;
                            }

                            break;
                        }
                    //Remote party is busy.
                    case Command.Bye:
                        {
                            //Check if the Bye command has indeed come from the user/IP with which we have
                            //a call established. This is used to prevent other users from sending a Bye, which
                            //would otherwise end the call.
                            if (IsServiceStarted && eMode == Mode.Client && receivedFromEP.Equals(serverEP))
                            {
                                bStop = true;
                                cGlobalVars.AddLogChat("Received by from server: Disconnecting");

                                //End the call.
                                UninitializeCall();
                            }
                            break;
                        }
                }

                byteData = new byte[1024];
                //Get ready to receive more commands.

                if (!bStop)
                    clientSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref receivedFromEP, new AsyncCallback(OnReceive), null);

            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message, "VoiceChat-OnReceive ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cGlobalVars.AddLogChat("VoiceChat-OnReceive () > " + ex.Message);
            }
        }
Beispiel #17
0
        /*
         * Commands are received asynchronously. OnReceive is the handler for them.
         */
        private void OnReceive(IAsyncResult ar)
        {
            //TODO: Switch Receive Commands

            try
            {
                EndPoint receivedFromEP = new IPEndPoint(IPAddress.Any, 0);

                //Get the IP from where we got a message.
                clientSocket.EndReceiveFrom(ar, ref receivedFromEP);

                //Convert the bytes received into an object of type Data.
                Data msgReceived = new Data(byteData);

                //Act according to the received message.
                switch (msgReceived.cmdCommand)
                {
                case Command.ChangeVocoderALaw:

                    if (IsServiceStarted && eMode == Mode.Client && receivedFromEP.Equals(serverEP))
                    {
                        cGlobalVars.AddLogChat("El servidor cambio el modo a ALaw");

                        //Cambiamos el combo box
                        SetCodecCombo(1);
                    }
                    break;

                case Command.ChangeVocoderNone:

                    if (IsServiceStarted && eMode == Mode.Client && receivedFromEP.Equals(serverEP))
                    {
                        cGlobalVars.AddLogChat("El servidor cambio el modo a None");
                        //cmbCodecs.SelectedIndex = 0;
                        SetCodecCombo(0);
                    }
                    break;

                case Command.ChangeVocoderuLaw:
                    if (IsServiceStarted && eMode == Mode.Client && receivedFromEP.Equals(serverEP))
                    {
                        cGlobalVars.AddLogChat("El servidor cambio el modo a uLaw");
                        SetCodecCombo(2);
                    }
                    break;

                //MODO SERVER: recepción de invitación por parte de cliente.
                case Command.Invite:
                {
                    if (IsServiceStarted && eMode == Mode.Server)
                    {
                        cGlobalVars.AddLogChat("Se ha conectado: " + receivedFromEP.ToString());
                        vocoder = msgReceived.vocoder;

                        lock (clientIPs)
                        {
                            if (!ExistsIp((IPEndPoint)receivedFromEP))
                            {
                                clientIPs.Add((IPEndPoint)receivedFromEP);
                            }
                        }

                        SendMessage(Command.OK, receivedFromEP);
                    }

                    break;
                }

                //CLIENTE: Respuesta del servidor de nuestra petición de conexión
                case Command.OK:
                {
                    if (eMode == Mode.PreClient && receivedFromEP.Equals(serverEP))
                    {
                        eMode = Mode.Client;
                    }

                    break;
                }

                //Remote party is busy.
                case Command.Bye:
                {
                    //Check if the Bye command has indeed come from the user/IP with which we have
                    //a call established. This is used to prevent other users from sending a Bye, which
                    //would otherwise end the call.
                    if (IsServiceStarted && eMode == Mode.Client && receivedFromEP.Equals(serverEP))
                    {
                        bStop = true;
                        cGlobalVars.AddLogChat("Received by from server: Disconnecting");

                        //End the call.
                        UninitializeCall();
                    }
                    break;
                }
                }

                byteData = new byte[1024];
                //Get ready to receive more commands.

                if (!bStop)
                {
                    clientSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref receivedFromEP, new AsyncCallback(OnReceive), null);
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message, "VoiceChat-OnReceive ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cGlobalVars.AddLogChat("VoiceChat-OnReceive () > " + ex.Message);
            }
        }
Beispiel #18
0
        /*
         * Commands are received asynchronously. OnReceive is the handler for them.
         */
        private void OnReceive(IAsyncResult ar)
        {
            try
            {
                if (receivedFromEP==null)
                {
                    receivedFromEP = new IPEndPoint(IPAddress.Any, 0);
                }

                //Get the IP from where we got a message.
                clientSocket.EndReceiveFrom(ar, ref receivedFromEP);

                //Convert the bytes received into an object of type Data.
                Data msgReceived = new Data(byteData);

                //Act according to the received message.
                switch (msgReceived.cmdCommand)
                {
                    //We have an incoming call.
                    case Command.Invite:
                        {
                            if (bIsCallActive == false)
                            {
                                //We have no active call.

                                //Ask the user to accept the call or not.
                                if (MessageBox.Show(msgReceived.strName + "邀请你进行语音通话.\r\n\r\n接受吗?",
                                    "通话邀请", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                                {
                                    SendMessage(Command.OK, receivedFromEP);
                                    vocoder = msgReceived.vocoder;
                                    otherPartyEP = receivedFromEP;
                                    otherPartyIP = (IPEndPoint)receivedFromEP;
                                    InitializeCall();
                                }
                                else
                                {
                                    //The call is declined. Send a busy response.
                                    SendMessage(Command.Busy, receivedFromEP);
                                }
                            }
                            else
                            {
                                //We already have an existing call. Send a busy response.
                                SendMessage(Command.Busy, receivedFromEP);
                            }
                            break;
                        }

                    //OK is received in response to an Invite.
                    case Command.OK:
                        {
                            //Start a call.
                            string ip = receivedFromEP.ToString().Split(':')[0];
                            //将远程同意邀请的用户IP写到教师机的  聊天室列表中
                            addChatRoom(ip, ((OnlineUser)(LoginRoler.OnlineUserDic[ip])).ChatName);

                            //更新在线用户的  isChating 值改成true
                            updateOnlineUser(ip,true);
                            //同时需要通知其他学生机更新目前最新的聊天室用户IP列表  而这个操作需要由一开始登录的Socket来做
                            updateNetNewChatRoomUsersToStudent();
                            loadOnlineUses();
                            InitializeCall();
                            break;
                        }

                    //Remote party is busy.
                    case Command.Busy:
                        {
                            MessageBox.Show("User busy.", "VoiceChat", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            break;
                        }

                    case Command.Bye:
                        {
                            //Check if the Bye command has indeed come from the user/IP with which we have
                            //a call established. This is used to prevent other users from sending a Bye, which
                            //would otherwise end the call.
                            if (receivedFromEP.Equals(otherPartyEP) == true)
                            {
                                //End the call.
                                UninitializeCall();
                            }
                            break;
                        }
                }

                byteData = new byte[1024];
                //Get ready to receive more commands.
                clientSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref receivedFromEP, new AsyncCallback(OnReceive), null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "VoiceChat-OnReceive ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #19
0
        private void Call()
        {
            try
            {
                //Get the IP we want to call.
                LogLine("Trying to make a call...");
                otherPartyIP = new IPEndPoint(IPAddress.Parse(Contacts.SelectedItem.ToString()), 3535);
                otherPartyEP = (EndPoint)otherPartyIP;

                //Get the vocoder to be used.
                if (radioButton4.Checked)
                {
                    vocoder = Vocoder.ALaw;
                }
                else if (radioButton5.Checked)
                {
                    vocoder = Vocoder.uLaw;
                }
                else if (radioButton6.Checked)
                {
                    vocoder = Vocoder.None;
                }

                CallButton.Enabled = false;
                this.Text = "Вызываем абонента... | Fenazy";
                //Send an invite message.
                lastcalled = Contacts.SelectedIndex;
                chats[Contacts.SelectedIndex] += DateTime.Now + " *Вы звоните абоненту*\r\n";
                UpdateChatText();
                tabControl1.SelectTab(1);
                SendMessage(Command.Invite, otherPartyEP);
                WaitForAnswerTimer.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка вызова | Fenazy", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #20
0
        /*
         * Commands are received asynchronously. OnReceive is the handler for them.
         */
        private void OnReceive(IAsyncResult ar)
        {
            try
             {

                 EndPoint receivedFromEP = new IPEndPoint(IPAddress.Any, 0);

                 //Get the IP from where we got a message.
                 clientSocket.EndReceiveFrom(ar, ref receivedFromEP);

                 //Convert the bytes received into an object of type Data.
                 Data msgReceived = new Data(byteData);

                 //Act according to the received message.
                 switch (msgReceived.cmdCommand)
                 {

                     case Command.ChangeVocoderALaw:
                         LogAppend("El servidor cambio el modo a ALaw");
                         break;
                     case Command.ChangeVocoderNone:
                         LogAppend("El servidor cambio el modo a None");
                         break;
                     case Command.ChangeVocoderuLaw:
                         LogAppend("El servidor cambio el modo a uLaw");
                         break;

                     //We have an incoming call.
                     case Command.Invite:
                         {
                             if (bIsServerStarted)
                             {

                                 LogAppend("Se ha conectado: " + receivedFromEP.ToString());
                                 vocoder = msgReceived.vocoder;

                                 lock (otherPartyIPs)
                                 {
                                     if (!ExistsIp((IPEndPoint)receivedFromEP))
                                         otherPartyIPs.Add((IPEndPoint)receivedFromEP);
                                 }

                                 SendMessage(Command.OK, receivedFromEP);

                             }

                             break;
                         }

                     //OK is received in response to an Invite.
                     case Command.OK:
                         {

                             if (!bIsServerStarted)
                             {

                                 eMode = Mode.Client;

                                 //Solamente puede recibir este parametro si no está en modo servidor
                                 lock (otherPartyIPs)
                                 {
                                     otherPartyIPs.Clear();
                                     otherPartyIPs.Add((IPEndPoint)receivedFromEP);
                                 }

                                 LogAppend("Connectado a : " + receivedFromEP.ToString());

                                 InitializeCall();

                             }

                             break;
                         }

                     //Remote party is busy.

                     case Command.Bye:
                         {
                             //Check if the Bye command has indeed come from the user/IP with which we have
                             //a call established. This is used to prevent other users from sending a Bye, which
                             //would otherwise end the call.
                             if (receivedFromEP.Equals(otherPartyEP) == true)
                             {
                                 //End the call.
                                 UninitializeCall();
                             }
                             break;
                         }
                 }

                 byteData = new byte[1024];
                 //Get ready to receive more commands.

                 if (!bStop)
                     clientSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref receivedFromEP, new AsyncCallback(OnReceive), null);
                 else
                     IsThreadReceiveCommandsEnd = true;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, "VoiceChat-OnReceive ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
        }
Beispiel #21
0
		public void Connect()
		{
			try
			{
				//Get the IP we want to connect.
				otherPartyIP = new IPEndPoint(IPAddress.Parse(IP), 1450);
				otherPartyEP = (EndPoint)otherPartyIP;

				//Get the vocoder to be used.
				if (Codec == "A-Law")
				{
					vocoder = Vocoder.ALaw;
				}
				else if (Codec == "u-Law")
				{
					vocoder = Vocoder.uLaw;
				}
				else if (Codec == "None")
				{
					vocoder = Vocoder.None;
				}

				//Send an invite message.
				SendMessage(Command.Invite, otherPartyEP);
			}
			catch (Exception ex)
			{
				//MessageBox.Show(ex.Message, "ThereMe - Connect ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
		}
Beispiel #22
0
        public void ChangeCodification(cChatEngine.Vocoder codification)
        {
            if (codification == cChatEngine.Vocoder.ALaw)
            {
                vocoder = cChatEngine.Vocoder.ALaw;
                cGlobalVars.AddLogChat("Se ha modificado codificación a: ALaw");
                if (eMode == cChatEngine.Mode.Server)
                {
                    lock (clientIPs)
                    {
                        for (int i = 0; i < clientIPs.Count; i++)
                            SendMessage(cChatEngine.Command.ChangeVocoderALaw, clientIPs[i]);
                    }

                }
            }
            else if (codification == cChatEngine.Vocoder.uLaw)
            {
                vocoder = Vocoder.uLaw;
                cGlobalVars.AddLogChat("Se ha modificado codificación a: uLaw");

                if (eMode == cChatEngine.Mode.Server)
                {
                    lock (clientIPs)
                    {
                        for (int i = 0; i < clientIPs.Count; i++)
                            SendMessage(cChatEngine.Command.ChangeVocoderuLaw, clientIPs[i]);
                    }

                }

            }
            else
            {
                vocoder = cChatEngine.Vocoder.None;
                cGlobalVars.AddLogChat("Se ha modificado codificación a: None");
                if (eMode == cChatEngine.Mode.Server)
                {
                    lock (clientIPs)
                    {
                        for (int i = 0; i < clientIPs.Count; i++)
                            SendMessage(cChatEngine.Command.ChangeVocoderNone, clientIPs[i]);
                    }

                }

            }
        }
Beispiel #23
0
        private void OnReceive(IAsyncResult ar)
        {
            try
            {
                EndPoint receivedFromEP = new IPEndPoint(IPAddress.Any, 0);

                //Get the IP from where we got a message.
                clientSocket.EndReceiveFrom(ar, ref receivedFromEP);

                //Convert the bytes received into an object of type Data.
                Data msgReceived = new Data(byteData);

                //Act according to the received message.
                switch (msgReceived.cmdCommand)
                {
                //We have an incoming call.
                case Command.Invite:
                {
                    if (bIsCallActive == false)
                    {
                        //We have no active call.

                        //Ask the user to accept the call or not.
                        if (MessageBox.Show("Call coming from " + msgReceived.strName + ".\r\n\r\nAccept it?",
                                            "VoiceChat", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            SendMessage(Command.OK, receivedFromEP);
                            vocoder      = msgReceived.vocoder;
                            otherPartyEP = receivedFromEP;
                            otherPartyIP = (IPEndPoint)receivedFromEP;
                            InitializeCall();
                            VideoCall();
                        }
                        else
                        {
                            //Now when The call is declined we Send a busy response to the client.
                            SendMessage(Command.Busy, receivedFromEP);
                        }
                    }
                    else
                    {
                        //Even if We already have an existing call then also we  Send a busy response.
                        SendMessage(Command.Busy, receivedFromEP);
                    }
                    break;
                }

                //OK is received in response to an Invite.
                case Command.OK:
                {
                    Thread init = new Thread(new ThreadStart(InitializeCall));
                    init.IsBackground = true;
                    init.Start();
                    VideoCall();
                    // WriteImage.Start();
                    //  Thread testthread = new Thread(new ThreadStart(VideoCall));
                    // testthread.IsBackground = true;
                    // testthread.Start();

                    // VideoCall();
                    break;
                }

                //The destination is busy.
                case Command.Busy:
                {
                    MessageBox.Show("User busy.", "VoiceChat", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    break;
                }

                case Command.Bye:
                {
                    if (receivedFromEP.Equals(otherPartyEP) == true)
                    {
                        //End the call.
                        UninitializeCall();
                    }
                    break;
                }
                }

                byteData = new byte[1024];
                //Get ready to receive more commands.
                clientSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref receivedFromEP, new AsyncCallback(OnReceive), null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "VoiceChat-OnReceive ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #24
0
 //Default constructor.
 public Data()
 {
     this.cmdCommand = Command.Null;
     this.strName = null;
     vocoder = Vocoder.ALaw;
 }
Beispiel #25
0
        private void cmbCodecs_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbCodecs.SelectedIndex == 1)
            {
                vocoder = Vocoder.ALaw;
                LogAppend("Se ha modificado codificación a: ALaw");

                if (eMode == Mode.Server)
                {
                    lock (otherPartyIPs)
                    {
                        for (int i = 0; i < otherPartyIPs.Count; i++)
                            SendMessage(Command.ChangeVocoderALaw, otherPartyIPs[i]);
                    }

                }

            }
            else if (cmbCodecs.SelectedIndex == 1)
            {
                vocoder = Vocoder.uLaw;
                LogAppend("Se ha modificado codificación a: uLaw");

                if (eMode == Mode.Server)
                {
                    lock (otherPartyIPs)
                    {
                        for (int i = 0; i < otherPartyIPs.Count; i++)
                            SendMessage(Command.ChangeVocoderuLaw, otherPartyIPs[i]);
                    }

                }

            }
            else
            {
                vocoder = Vocoder.None;
                LogAppend("Se ha modificado codificación a: None");
                if (eMode == Mode.Server)
                {
                    lock (otherPartyIPs)
                    {
                        for (int i = 0; i < otherPartyIPs.Count; i++)
                            SendMessage(Command.ChangeVocoderNone, otherPartyIPs[i]);
                    }

                }

            }
        }