public void sendInvite()
 {
     notyet = false;
     StartCoroutine(chatConnect());
     StopCoroutine(RecordVoice.record());
     StopCoroutine(receive());
     StopCoroutine(receiveWithLag());
 }
    IEnumerator chatConnect()
    {
        yield return(new WaitForSeconds(1.1f));

        try{
            notyet = true;
            string ipaddress  = ipAd.text;                       //"192.168.1.255";
            int    port       = int.Parse(portField.text);
            int    portToSend = int.Parse(portToSendField.text); //10002;
            Byte[] sendBytes  = Encoding.ASCII.GetBytes("message.text");
            minUdpClient     = new UdpClient(port);
            RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);             //Creates an IPEndPoint to record the IP Address and port number of the sender.
            SendIPEndPoint   = new IPEndPoint(IPAddress.Parse(ipaddress), portToSend);
            int loops = 0;
            Debug.Log("Starting");
            StartCoroutine(RecordVoice.record());
            StartCoroutine(receive());
            status.text = ("connecting");
        } catch (Exception e) {
            //Debug.Log(String.Format("Error: {0}", e.Message));
            status.text = ("connecting problem " + e.Message);
        }
        while (notyet)
        {
            /*
             * minUdpClient.Send (sendBytes, sendBytes.Length, SendIPEndPoint);
             * //System.Threading.Thread.Sleep (1000);
             * //Debug.Log("sending UDP port : " + ((IPEndPoint)minUdpClient.Client.LocalEndPoint).Port.ToString());
             * try {
             *      if (minUdpClient.Available > 0) {
             *              receiveBytes = minUdpClient.Receive (ref RemoteIpEndPoint);
             *              String returnData = Encoding.ASCII.GetString (receiveBytes);
             *              receivedMessage.text = ("Data Received:\n" + returnData + "\nfrom ip " + RemoteIpEndPoint.Address.ToString() + " from port " + RemoteIpEndPoint.Port.ToString ());
             *              status.text = ("UDP Connection Successful. Sending message and receiving message" +" ("+loops+")");
             *              //minUdpClient.Close ();
             *              //Console.ReadLine ();
             *              //notyet = false;
             *      } else {
             *              status.text = ("Sending message and waiting to receive message" +" ("+loops+")");
             *      }
             * } catch (Exception e) {
             *      status.text = (e.ToString ());
             * }*/
            yield return(new WaitForSeconds(1));
        }
        minUdpClient.Close();
        status.text = ("Disconnected");
    }