Exemple #1
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.
                VoiceCommon.Data msgReceived = new VoiceCommon.Data(byteData);

                //Act according to the received message.
                switch (msgReceived.cmdCommand)
                {
                //MODO SERVER: recepción de invitación por parte de cliente.
                case VoiceCommon.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(VoiceCommon.Command.OK, receivedFromEP);
                    }

                    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);
            }
        }
Exemple #2
0
        /*
         * Send a message to the remote party.
         */
        private void SendMessage(VoiceCommon.Command cmd, EndPoint sendToEP)
        {
            try
            {
                //Create the message to send.
                VoiceCommon.Data msgToSend = new VoiceCommon.Data();

                msgToSend.strName    = Nickname; //Name of the user.
                msgToSend.cmdCommand = cmd;      //Message to send.
                msgToSend.vocoder    = vocoder;  //Vocoder to be used.

                byte[] message = msgToSend.ToByte();

                //Send the message asynchronously.
                clientSocket.BeginSendTo(message, 0, message.Length, SocketFlags.None, sendToEP, new AsyncCallback(OnSend), null);
            }
            catch (Exception ex)
            {
                cGlobalVars.AddLogChat("VoiceChat-SendMessage > " + ex.Message);
                //MessageBox.Show(ex.Message, "VoiceChat-SendMessage ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #3
0
        /*
          * Send a message to the remote party.
          */
        private void SendMessage(VoiceCommon.Command cmd, EndPoint sendToEP)
        {
            try
            {
                //Create the message to send.
                VoiceCommon.Data msgToSend = new VoiceCommon.Data();

                msgToSend.strName = Nickname;   //Name of the user.
                msgToSend.cmdCommand = cmd;         //Message to send.
                msgToSend.vocoder = vocoder;        //Vocoder to be used.

                byte[] message = msgToSend.ToByte();

                //Send the message asynchronously.
                clientSocket.BeginSendTo(message, 0, message.Length, SocketFlags.None, sendToEP, new AsyncCallback(OnSend), null);
            }
            catch (Exception ex)
            {
                cGlobalVars.AddLogChat("VoiceChat-SendMessage > " + ex.Message);
                //MessageBox.Show(ex.Message, "VoiceChat-SendMessage ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #4
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.
                VoiceCommon.Data msgReceived = new VoiceCommon.Data(byteData);

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

                    //MODO SERVER: recepción de invitación por parte de cliente.
                    case VoiceCommon.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(VoiceCommon.Command.OK, receivedFromEP);

                            }

                            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);
            }
        }
Exemple #5
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.
                VoiceCommon.Data msgReceived = new VoiceCommon.Data(byteData);

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

                    case VoiceCommon.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 VoiceCommon.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 VoiceCommon.Command.ChangeVocoderuLaw:
                        if (IsServiceStarted && eMode == Mode.Client && receivedFromEP.Equals(serverEP))
                        {
                            cGlobalVars.AddLogChat("El servidor cambio el modo a uLaw");
                            SetCodecCombo(2);

                        }
                        break;

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

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

                            break;
                        }
                    //Remote party is busy.
                    case VoiceCommon.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);
            }
        }
Exemple #6
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.
                VoiceCommon.Data msgReceived = new VoiceCommon.Data(byteData);

                //Act according to the received message.
                switch (msgReceived.cmdCommand)
                {
                case VoiceCommon.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 VoiceCommon.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 VoiceCommon.Command.ChangeVocoderuLaw:
                    if (IsServiceStarted && eMode == Mode.Client && receivedFromEP.Equals(serverEP))
                    {
                        cGlobalVars.AddLogChat("El servidor cambio el modo a uLaw");
                        SetCodecCombo(2);
                    }
                    break;


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

                    break;
                }

                //Remote party is busy.
                case VoiceCommon.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);
            }
        }