コード例 #1
0
ファイル: Form1.cs プロジェクト: johndepo/UniProject
        //This is to run in background
        //by new thread
        public void GetMessage()
        {
            int nc = 0;

            try
            {
                while (!connection.Connected) { }
                //state = 3;
                stream = connection.GetStream();
                //this.Invoke(new MethodInvoker(DisplayState));
                while (connection.Connected)
                {
                    if (connection.Available > 0)
                    {
                        nc = stream.Read(inBuff, 0, IOBSize); //break point
                        inMSG = Encoding.ASCII.
                            GetString(inBuff,
                                        0, nc);

                        string[] command = inMSG.Split('.');
                        string data = command[1];

                        switch (command[0])
                        {
                            case "User has been authenticated":
                                MessageBox.Show(inMSG);
                                break;
                            case "Username or password is incorrect":
                                MessageBox.Show(inMSG);
                                break;
                            case "Thank You!":
                                MessageBox.Show("Logged out");
                                break;
                            case "tutorialList":

                                lst_TutorialUpdate method = new lst_TutorialUpdate(showTutorials);
                                lst_Tutorials.Invoke(method, new object[] {data});

                                break;
                            case "studentSessionRequest":
                                lbl_SessionUpdate m = new lbl_SessionUpdate(showSession);
                                lbl_Session.Invoke(m, new object[] { data });
                                break;
                            case "Tutorial Change successful":
                                MessageBox.Show(inMSG);
                                break;
                            case "Tutorial change unsuccessful":
                                MessageBox.Show(inMSG);
                                break;
                            case "TutorialStudents":
                                //MessageBox.Show(inMSG);
                                lst_StudentUpdate s = new lst_StudentUpdate(showStudent);
                                lst_Students.Invoke(s, new object[] { data });
                                break;
                            case "foundStudent":
                                lst_StudentUpdate g = new lst_StudentUpdate(showStudent);
                                lst_Students.Invoke(g, new object[] { data });
                                break;
                            case "foundStudentName":
                                lbl_HeaderUpdate h = new lbl_HeaderUpdate(showName);
                                lbl_Header.Invoke(h, new object[] { data });
                                break;
                        }
                    }
                    //break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    "Error: getMessage   " +
                    ex.Message);
            }
        }
コード例 #2
0
        public void GetMessage()
        //This is to run in background
        //by new thread
        {
            int nc = 0;

            try
            {
                while (!connection.Connected)
                {
                }
                //state = 3;
                stream = connection.GetStream();
                //this.Invoke(new MethodInvoker(DisplayState));
                while (connection.Connected)
                {
                    if (connection.Available > 0)
                    {
                        nc    = stream.Read(inBuff, 0, IOBSize); //break point
                        inMSG = Encoding.ASCII.
                                GetString(inBuff,
                                          0, nc);

                        string[] command = inMSG.Split('.');
                        string   data    = command[1];


                        switch (command[0])
                        {
                        case "User has been authenticated":
                            MessageBox.Show(inMSG);
                            break;

                        case "Username or password is incorrect":
                            MessageBox.Show(inMSG);
                            break;

                        case "Thank You!":
                            MessageBox.Show("Logged out");
                            break;

                        case "tutorialList":

                            lst_TutorialUpdate method = new lst_TutorialUpdate(showTutorials);
                            lst_Tutorials.Invoke(method, new object[] { data });

                            break;

                        case "studentSessionRequest":
                            lbl_SessionUpdate m = new lbl_SessionUpdate(showSession);
                            lbl_Session.Invoke(m, new object[] { data });
                            break;

                        case "Tutorial Change successful":
                            MessageBox.Show(inMSG);
                            break;

                        case "Tutorial change unsuccessful":
                            MessageBox.Show(inMSG);
                            break;

                        case "TutorialStudents":
                            //MessageBox.Show(inMSG);
                            lst_StudentUpdate s = new lst_StudentUpdate(showStudent);
                            lst_Students.Invoke(s, new object[] { data });
                            break;

                        case "foundStudent":
                            lst_StudentUpdate g = new lst_StudentUpdate(showStudent);
                            lst_Students.Invoke(g, new object[] { data });
                            break;

                        case "foundStudentName":
                            lbl_HeaderUpdate h = new lbl_HeaderUpdate(showName);
                            lbl_Header.Invoke(h, new object[] { data });
                            break;
                        }
                    }
                    //break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    "Error: getMessage   " +
                    ex.Message);
            }
        }