Exemplo n.º 1
0
        /// <summary>
        /// Constructor used for Multi-user Spreadsheet
        /// </summary>
        public SSForm(NetworkWarden ward, string filename)
        {
            InitializeComponent();

            istyping            = false;
            oldAddress          = "A1";
            personalSpreadsheet = new Spreadsheet(validAddress, s =>
                                                  s.ToUpper(), "PS6");
            this.Text       = filename;
            addressBox.Text = "A1";
            warden          = ward;
            warden.callNext = Sent_Message;

            // Set warden callback function for server messages
            listenWarden          = new NetworkWarden(warden.socket, warden.ID);
            listenWarden.callNext = Receive_Message;

            // Send the filename to the server
            Networking.getData(listenWarden);
            System.Threading.Thread.Sleep(800);
            try
            {
                Networking.Send(warden, "Connect\t" + filename + "\t\n");
            }
            catch (Exception err)
            {
                while (MessageBox.Show("Server is down, application will now close.", "", MessageBoxButtons.OK) == 0)
                {
                }
                Application.Exit();
            }
        }
Exemplo n.º 2
0
        /********************************************************************************************
        * Network Comunication Section - Server -> Client
        ********************************************************************************************/

        /// <summary>
        /// Receive hub - decodes message and activate proper command
        /// </summary>
        public void Receive_Message(NetworkWarden ward)
        {
            if (ward.buffString == null)
            {
                return;
            }
            string msg = ward.buffString;

            Array.Clear(ward.buffer, 0, ward.buffer.Length);
            ward.buffString = "";
            ward.message.Clear();
            string[] parsedMsg = msg.Split('\t');

            switch (parsedMsg[0])
            {
            case "Change":
                this.Invoke(new MethodInvoker(() =>
                                              Receive_Change(parsedMsg)));
                break;

            case "IsTyping":
                this.Invoke(new MethodInvoker(() => Receive_IsTyping(parsedMsg)));
                break;

            case "DoneTyping":
                this.Invoke(new MethodInvoker(() => Receive_DoneTyping(parsedMsg)));
                break;

            default:
                // error in Received message: gracefully close everything
                System.Diagnostics.Debug.Print("Bad Message Recieved");
                break;
            }
            Networking.getData(ward);
        }