高手请进啊!!急求答案!!
我运行的一个程序为什么要下载是下不了啊,客户端和服务器已经连接上了,要在服务器端下的文件也已显示就是下的时候出现问题,代码如下:望解答啊private void button1_Click(object sender, System.EventArgs e)
{
int port=3232; //默认端口为3232
IPAddress myIP=IPAddress.Parse("10.1.11.191"); //默认IP地址
try
{
myIP=IPAddress.Parse(textBox2.Text);
}
catch
{
MessageBox.Show("您输入的IP地址格式不正确!");
}
client =new TcpClient();
try
{
port=Int32.Parse(textBox3.Text);
}
catch
{
MessageBox.Show("请输入整数。");
}
try
{
if(textBox2.Text!="")
{
client.Connect(myIP,port);
}
else
{
if(textBox1.Text!="")
{
client.Connect(textBox1.Text,port);
}
else
{
MessageBox.Show("服务器名称和服务器IP地址不能都空!");
return; //返回
}
}
statusBarPanel1.Text="与服务器建立连接";
netStream=client.GetStream(); //获取网络流
byte[] bb=new byte[6400];
i=netStream.Read(bb,0,6400); //客户端读取服务器端服务器文件名
string ss=System.Text.Encoding.BigEndianUnicode.GetString(bb);
richTextBox1.AppendText(ss); //写进richTextBox1
int j=richTextBox1.Lines.Length;
for(int k=0;k<j-1;k++)
{
comboBox1.Items.Add(richTextBox1.Lines[k]);
}
comboBox1.Text=comboBox1.Items[0].ToString();
}
catch(Exception ee)
{
MessageBox.Show(ee.Message);
}
}
private void button2_Click(object sender, System.EventArgs e)
{
if(saveFileDialog1.ShowDialog()==DialogResult.OK)
{
System.IO.FileStream fs = (System.IO.FileStream)saveFileDialog1.OpenFile();
filestream=new FileStream(saveFileDialog1.FileName,FileMode.OpenOrCreate,FileAccess.Write); //构造新的文件流
netStream=client.GetStream();
string down=comboBox1.Text+"\r\n";
byte[] by=System.Text.Encoding.BigEndianUnicode.GetBytes(down.ToCharArray());
netStream.Write(by,0,by.Length); //向服务器发送要下载的文件名
netStream.Flush();
Thread thread=new Thread(new ThreadStart(download)); //启动接收文件的线程
thread.Start();
}
}
private void download()
{
down(ref netStream);
}
private void down(ref NetworkStream stream)
{
int length=1024;
byte[] bye=new byte[1024];
int tt=stream.Read(bye,0,length);
while(tt>0) //下行循环读取网络流并写进文件
{
string ss=System.Text.Encoding.ASCII.GetString(bye);
int x=ss.IndexOf("<EOF>");
if(x!=-1) //字节流中有<EOF>
{
filestream.Write(bye,0,x);
filestream.Flush();
break;
}
else //没到结尾
{
filestream.Write(bye,0,tt);
filestream.Flush();
}
tt=stream.Read(bye,0,length);
}
filestream.Close();
MessageBox.Show("下载完毕!");
}
private void button3_Click(object sender, System.EventArgs e)
{
try
{
netStream=client.GetStream();
string clo="@@@@@@"+"\r\n";
byte[] by=System.Text.Encoding.BigEndianUnicode.GetBytes(clo.ToCharArray());
netStream.Write(by,0,by.Length);
netStream.Flush();
client.Close();
statusBarPanel1.Text="与服务器断开连接";
}
catch
{
}
}
}
}
这是哪的问题啊?SaveFileDialog1么?
补充:.NET技术 , C#