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()); }
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!"); }
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!"); }