Пример #1
0
        public void Listen()
        {
            while (true)
            {
                var    data         = new Byte[256];
                String responseData = String.Empty;

                var bytes = stream.Read(data, 0, data.Length);
                responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
                string[] words = responseData.Split(':');
                Console.WriteLine(responseData);

                if (words[0] == "CALL")
                {
                    //CALL:Korzych:Dellor:127.0.0.1:8001 - Serwer->Korzych

                    string message = words[2] + " wants to talk. Do you want to accept?";
                    string caption = "Incoming Call";
                    var    result  = MessageBox.Show(message, caption,
                                                     MessageBoxButtons.YesNo,
                                                     MessageBoxIcon.Question);

                    // If the no button was pressed ...
                    if (result == DialogResult.No)
                    {
                        simpleSound.Stop();

                        // cancel the closure of the form.
                        var msg = "DENY:" + words[2];
                        data = System.Text.Encoding.ASCII.GetBytes(msg);
                        stream.Write(data, 0, data.Length);
                    }
                    else
                    {
                        //CALL:Korzych:Dellor:127.0.0.1:8001
                        simpleSound.Stop();
                        listenport = FreePort();
                        var udpPort    = Int32.Parse(words[4]);
                        var nickname   = words[2];
                        var udpAddress = words[3];
                        //UdpClient listener = new UdpClient(0)
                        var msg = "CONN:" + words[2] + ":" + listenport.ToString();
                        data = System.Text.Encoding.ASCII.GetBytes(msg);
                        stream.Write(data, 0, data.Length);

                        SessionForm sessionForm = new SessionForm(udpPort, nickname, udpAddress, listenport, tcpClient, username);
                        GuiClient.RunPanel(sessionForm);
                    }
                }
                else if (words[0] == "LIST")
                {
                    var delUpdateBox = new delUpdateBox(UpdateList);
                    this.users.BeginInvoke(delUpdateBox, responseData);
                }
                else if (words[0] == "CONN")
                {
                    //CONN:DELLOR:127.0.0.1:2001- Connect - Serwer->Dellor
                    // listenport = FreePort();
                    var nickname   = words[1];
                    var udpAddress = words[2];
                    var udpPort    = Int32.Parse(words[3]);
                    //var msg = "CONN:" + words[2] + ":"+listenport.ToString();
                    singalSound.Stop();
                    simpleSound.Stop();

                    SessionForm sessionForm = new SessionForm(udpPort, callUser, udpAddress, listenport, tcpClient, username);
                    GuiClient.RunPanel(sessionForm);
                }
                else if (words[0] == "DENY")
                {
                    MessageBox.Show("User Rejected Your Call");
                }
            }
        }
Пример #2
0
 public static void RunPanel(SessionForm form)
 {
     form.ShowDialog();
 }