Exemplo n.º 1
0
        public void receive()
        {
            byte[] newImage = new byte[1723446];

            while (true)
            {
                byte[] bytesFrom = new byte[(int)client.ReceiveBufferSize];
                serverStream.Read(bytesFrom, 0, (int)client.ReceiveBufferSize);

                string   response       = Encoding.ASCII.GetString(bytesFrom);
                string[] response_parts = response.Split('|');

                if (response_parts.Length > 0)
                {
                    switch (response_parts[0])
                    {
                    case "2":         //Receive Chat
                        activeForm.Invoke((MethodInvoker) delegate()
                        {
                            activeForm.chatMessagesLocal.Add(new Tuple <string, string>(response_parts[1], response_parts[2]));
                            activeForm.repopulateChat();
                        });
                        break;

                    case "3":         //Last word was correct
                        activeForm.Invoke((MethodInvoker) delegate()
                        {
                            activeForm.chatMessagesLocal.Add(new Tuple <string, string>(response_parts[1], response_parts[2]));
                            activeForm.setAnswer();
                        });
                        break;

                    case "4":         //Receive the super secret word
                        isActiveClient = true;

                        activeForm.Invoke((MethodInvoker) delegate()
                        {
                            activeForm.setWord(response_parts[1]);
                        });
                        break;

                    case "6":         //Recieve Clear image command

                        activeForm.Invoke((MethodInvoker) delegate()
                        {
                            activeForm.clearImage();
                        });
                        break;

                    case "9":     //Receive Image Point

                        activeForm.Invoke((MethodInvoker) delegate()
                        {
                            activeForm.addToImage(JsonConvert.DeserializeObject <ImagePoint>(response_parts[1]));
                        });
                        break;

                    case "10":     //Receive Image Point

                        activeForm.Invoke((MethodInvoker) delegate()
                        {
                            isActiveClient = false;
                            activeForm.clearImage();
                        });

                        break;
                    }
                }
            }
        }