コード例 #1
0
ファイル: MiddleController.cs プロジェクト: 0000duck/bird
        public static MiddleController getInstance()
        {
            if (instance == null)
            {
                instance = new MiddleController();
            }

            return(instance);
        }
コード例 #2
0
        public bool isTransactionGoing()
        {
            int progressOfRunnigQ = MiddleController.getInstance().fileShareController.getOverallProgress();

            if (progressOfRunnigQ > 0 && progressOfRunnigQ != 100)
            {
                return(true);
            }
            return(false);
        }
コード例 #3
0
ファイル: Reciever.cs プロジェクト: 0000duck/bird
//        private void confirmConnectionToConnectedDevice(Socket socket)
//        {
//            byte[] sendBuffer;
//
//            sendBuffer =
//                Encoding.Default.GetBytes(settings.Default.controlPrefix + Control.ConnectedCccccc.ToString() +
//                                          settings.Default.controlPostfix);
//            try
//            {
//                socket.Send(sendBuffer, 0, sendBuffer.Length, 0);
//            }
//            catch (Exception e)
//            {
//                Console.WriteLine(e);
//                throw;
//            }
//        }

        private void receiveTextMessage(string id, Socket socket)
        {
            //byte[] sendBuffer = null;


            byte[] recievedBuffer = new byte[255];

            try
            {
                if (socket.Connected && recievedBuffer != null)

                {
                    int receivedSize = socket.Receive(recievedBuffer, 0, recievedBuffer.Length, 0); //need fixed when forced closed
                    Array.Resize(ref recievedBuffer, receivedSize);

                    string receivedText = Encoding.Default.GetString(recievedBuffer);

                    //checking for control msgs
                    string text = Encoder.getInstance().checkForControl(id, socket, receivedText);


                    //then this passes only msgs that are not control msgs to forward.
                    if (text.Length > 0)
                    {
                        //decrypting function here
                        //string decrypted= EncryptDecrypt.Decrypt(receivedText);


                        OnTextMessageReceived(id, receivedText);
                        //text msg processing loogic here
                        Console.WriteLine("Recieved: {0}\nfrom: {1}", text, id); //show in console
                    }
                }
            }
            catch (Exception e)
            {
                socket.Close();
                MiddleController.getInstance().disconnectHandle(id);
                Console.WriteLine(e);
            }
        }