Подскажите почему не осуществляется повторная загрузка, первый файл нормально скачивается, а вот когда пытаюсь загрузить другой файл или в другое место ничего не происходит
private void btnServer_Click(object sender, EventArgs e)
{
Server = new TcpListener(IPAddress.Any, 6785);
Server.Start();
thServer = new Thread(() =>
{
remoteClient = Server.AcceptTcpClient();
SendData(soob, GetLocDir());
byte[] buffer = new byte[2048];
while (remoteClient.Connected)
{
Array.Clear(buffer, 0, buffer.Length);
remoteClient.GetStream().Read(buffer, 0, buffer.Length);
string strData = Encoding.Default.GetString(buffer);
int b = strData.IndexOf("\0");
b = b - 3;
var messege = strData.Substring(0, 3);
strData = strData.Substring(3, b);
this.Invoke((Action)(() =>
{
if (messege == soob)
{
try
{
string poddir = String.Join("/", Directory.GetDirectories(strData));
string file = String.Join("/", Directory.GetFiles(strData));
SendData(soob, poddir + "/" + file);
}
catch (Exception) { }
}
else if (messege == info)///
{
FileInfo inf = new FileInfo(strData);
SendData(info, inf.Name + "@" + Convert.ToString(inf.Length));
FileStream Stream = File.OpenRead(strData);
int BytesRead = -1;
while (BytesRead != 0)
{
byte[] Buffer = new byte[65535];
BytesRead = Stream.Read(Buffer, 0, 65535);
if (localClient != null && localClient.Connected)
localClient.GetStream().Write(Buffer, 0, Buffer.Length);
else if (remoteClient != null && remoteClient.Connected)
remoteClient.GetStream().Write(Buffer, 0, Buffer.Length);
}
Stream.Close();
}
}));
}
});
thServer.Start();
}
FileStream Writing = null;
string nam = ""; int size = 0;
private void btnConnect_Click(object sender, EventArgs e)
{
localClient = new TcpClient();
localClient.Connect("127.0.0.1", 6785);
thClient = new Thread(() =>
{
byte[] buffer = new byte[80000];
while (localClient.Connected)
{
Array.Clear(buffer, 0, buffer.Length);
localClient.GetStream().Read(buffer, 0, 80000);
string strData = Encoding.Default.GetString(buffer);
var messege = strData.Substring(0, 3);
this.Invoke((Action)(() =>
{
if (messege == soob)
{
int b = strData.IndexOf("\0");
b = b - 3;
strData = strData.Substring(3, b);
listView1.Clear();
string[] tx = strData.Split('/');
foreach (string s in tx)
{
listView1.Items.Add(s, 1);
ls.Add(s);
}
}
else if (messege == info)
{
int b = strData.IndexOf("\0");
b = b - 3;
strData = strData.Substring(3, b);
string[] tx = strData.Split('@');
nam = tx[0];
size = Convert.ToInt32(tx[1] + 5);
textBox1.Text = tx[0];
textBox2.Text = tx[1];
}
else
{
if (Writing == null)
{
Writing = File.OpenWrite(path1 + "\\" + nam);
}
Writing.Write(buffer, 0, buffer.Length);
if (buffer.Length < 65535) Writing.Close();
}
}));
}
});
thClient.Start();
SendData(soob, GetLocDir());
}