예제 #1
0
        public void Process(Socket workerSock)
        {
            var remote = workerSock.RemoteEndPoint as IPEndPoint;

            Console.WriteLine("{0} want to download faces!", remote.Address.ToString());

            DownloadFacesMsg m = new DownloadFacesMsg();

            m.ReceiveFrom(workerSock);

            var files = Directory.GetFiles("Faces", "*.face");

            foreach (var file in files)
            {
                if (m.FaceNameList != null)
                {
                    var n = Path.GetFileNameWithoutExtension(file);
                    if (m.FaceNameList.Contains(n))
                    {
                        continue;
                    }
                }
                FileMsg msg = new FileMsg(file, "server");
                msg.Send(workerSock);
            }
            Console.WriteLine("{0} download faces OK!", remote.Address.ToString());
        }
예제 #2
0
파일: Client.cs 프로젝트: xxu10/C--Chat
        private void SendFile(string filePath = @"E:\Jellyfish.jpg", int step = 8192)
        {
            if (!File.Exists(filePath))
            {
                Console.WriteLine(">File {0} not exist!", filePath);
                return;
            }
            FileMsg msg = new FileMsg(filePath, UserService.LoginUserName, step);
            var     r   = msg.Send(serverSock);

            Console.WriteLine(r ? ">File send complete!" : ">Lost connection!");
        }
예제 #3
0
        public void SendFile(string friend, string filePath, int step = 8192)
        {
            var f = UserService.CurrentUsersFriend.Find(u => u.UserName == friend);

            if (f == null)
            {
                Console.WriteLine("You don't have this friend!");
                return;
            }
            if (!File.Exists(filePath))
            {
                Console.WriteLine(">File {0} not exist!", filePath);
                return;
            }
            Socket serverSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            var    end        = f.IPEnd;

            end.Port = FILE_TCP_PORT;
            serverSock.Connect(end);
            FileMsg msg = new FileMsg(filePath, UserService.LoginUserName, step);
            var     r   = msg.Send(serverSock);

            Console.WriteLine(r ? ">File send complete!" : ">Lost connection!");
        }