private void Download(DownloadableFile file) { try { TcpClient client = new TcpClient(IPBuilder.GetIP()); IPEndPoint serverIP = IPBuilder.GetIP(file.IP, file.Port); client.Connect(serverIP); client.Client.ReceiveTimeout = 7000; client.Client.SendTimeout = 7000; MyStreamIO myStream = new MyStreamIO(client.GetStream()); myStream.Write("<isClient>"); myStream.GetNEXT(); myStream.Write(file.FileName); string rely = myStream.ReadString(); if (rely != "<fileFound>") { client.GetStream().Close(); client.Close(); return; } IPEndPoint udpClientIP = IPBuilder.GetIP(); UdpClient udpClient = new UdpClient(udpClientIP); myStream.Write(udpClientIP.Address.ToString()); string udpListenerIP = myStream.ReadString(); myStream.Write(udpClientIP.Port); int udpListenerPort = myStream.ReadInt(); client.GetStream().Close(); client.Close(); UdpDownload(udpClient, IPBuilder.GetIP(udpListenerIP, udpListenerPort), file); udpClient.Close(); } catch (Exception e) { MessageBox.Show(e.Message, "Client error: when getting file info for download from file server"); } }
private IPEndPoint GetServerIP() { IPEndPoint serverIP = IPBuilder.GetIP(MainServerIP.Text, int.Parse(MainServerPort.Text)); return(serverIP); }