SetIEPConvAudio() public method

public SetIEPConvAudio ( IPEndPoint iep ) : void
iep System.Net.IPEndPoint
return void
Beispiel #1
0
 void RemoveUsrReference()
 {
     try{
         User usr = Program.MainForm.GetUserFromIP(m_clientSocket.RemoteEndPoint.ToString());
         if (usr != null)
         {
             usr.SetIEPConvVideo(null);
             usr.SetIEPConvAudio(null);
         }
     }
     catch (Exception Ex) {
     }
 }
Beispiel #2
0
        /// <summary>
        /// UDP Server Thread for audio frames
        /// </summary>
        private void UDPThreadAudio()
        {
            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            sock.ReceiveBufferSize = 10000000;
            sock.ReceiveTimeout    = 900;
            IPEndPoint iep = new IPEndPoint(IPAddress.Any, _iPortAudio);

            sock.Bind(iep);
            EndPoint ep = (EndPoint)iep;

            int iRead;

            byte[]     data = new byte[10000];
            IPEndPoint iepConv;

            System.Text.Encoding enc;
            enc = System.Text.Encoding.ASCII;
            while (!_bStopServer)
            {
                try
                {
                    iRead = sock.ReceiveFrom(data, ref ep);
                    if (iRead > 0)
                    {
                        //Console.WriteLine("Thread Audio:" + iRead.ToString());

                        /*int iCnt = data[2];
                         * iCnt <<= 8;
                         * iCnt |= data[1];*/
                        switch (data[0])
                        {
                        case CMD_ECHO:
                            sock.SendTo(data, iRead, SocketFlags.None, ep);
                            Program.MainForm.UpdateBytesRX(iRead);
                            break;

                        case CMD_FRM_AUDIO:
                            User usr = Program.MainForm.GetUserFromIPNoPort(ep.ToString());
                            //Console.WriteLine(usr.GetUser() + " > Audio ");
                            iepConv = usr.GetIEPConvAudio();
                            if (iepConv != null)
                            {
                                sock.SendTo(data, iRead, SocketFlags.None, iepConv);
                            }
                            break;

                        case CMD_BIND_USER:
                            data[iRead] = 0;
                            string sTmp        = enc.GetString(data, 1, iRead - 1);
                            User   usrReceiver = Program.MainForm.GetUser(sTmp);
                            User   usrCaller   = Program.MainForm.GetUserFromIPNoPort(ep.ToString());
                            if (usrReceiver != null)
                            {
                                usrCaller.SetIepAudio(ep.ToString());
                                usrCaller.SetIEPConvAudio(usrReceiver.GetIEPAudio());
                                String sCal = usrCaller.GetIEPVideo().Address + ":" + usrCaller.GetIEPVideo().Port;
                                String sDst = usrReceiver.GetIEPVideo().Address + ":" + usrReceiver.GetIEPVideo().Port;
                                Program.MainForm.AddLog("AUDIO BINDING :" + usrCaller.GetUser() + " " + sCal + "-> " + usrReceiver.GetUser() + " " + sDst, "");

                                data[1] = ACK;
                                sock.SendTo(data, 2, SocketFlags.None, ep);
                            }
                            else
                            {
                                Program.MainForm.AddLog(usrCaller.GetUser() + " CANNOT AUDIO BIND ", "");
                                data[1] = NACK;
                                sock.SendTo(data, 2, SocketFlags.None, ep);
                            }
                            break;
                        }
                    }
                }
                catch (Exception)
                {
                }
            }
            sock.Close();
        }