예제 #1
0
        public void ReceiveFile()
        {
            string output;

            SendMessage("SEND");

            //Receiveing data
            output = ReceiveMessage();
            string[] FilenameChecksum = output.Split('$');


            string fileName = string.Format(@"{0}\{1}", currentDir.FullName, FilenameChecksum[0]);
            string samefile;

            if (File.Exists(fileName))
            {
                SendMessage("FILE_EXIST");   //sending client status
                output = ReceiveMessage();
                if (output.Equals("NO"))
                {
                    return;
                }
                SendMessage("ALLOK");
            }
            else if ((samefile = DuplicateFileCollection.CheckFileIsDuplicate(FilenameChecksum[1])) != null)
            {
                SendMessage(samefile);   //sending client status
                output = ReceiveMessage();
                if (output.Equals("NO"))
                {
                    return;
                }
                SendMessage("ALLOK");
            }
            else
            {
                SendMessage("ALLOK");
            }

            int size = Convert.ToInt32(ReceiveMessage());

            byte[] bb = new byte[size];
            SendMessage("SENDFILE");
            int k = socket.Receive(bb);

            File.WriteAllBytes(fileName, bb);
            SendMessage(currentDir.Name);
        }
예제 #2
0
        public ServerSocket()
        {
            // Get Local Ip Address
            IPAddress  = GetLocalIPAddress();
            PortNumber = 55555;
            socket     = null;
            listener   = null;

            rootFolder = new Dictionary <string, string>();
            rootFolder.Add("Desktop", @"C:\Users\Rohit\Desktop");
            rootFolder.Add("Basic language", @"H:\Basic language");


            // Thread t1 = new Thread(() =>
            //{
            foreach (var item in rootFolder.Values)
            {
                DuplicateFileCollection.SearchDuplicateFile(item);
            }
            //});
        }