写一个邮件收发系统,用pop3读取信息
user和password认证显示成功,但是执行STAT或者LIST就报错
报错信息
Exception thrown:'System.IO.IOException' in System.dll
无法将数据写入传输连接:你的主机中的软件已经中断了一个已建立的连接
目前试过的方法:关闭防火墙
另外我还写了Networkstream.canwrite判断是否能写,是可以写的,但是运行到写入的句就报错
代码
private void button10_Click(object sender, EventArgs e)
{
//将光标置为等待状态
Cursor cr = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
POPserver = "pop.163.com";
user = "tayreuier@163.com";
password = "ihateyou44283968";
TcpClient receiver = new TcpClient(POPserver, 110);
Byte[] outbytes;
string input;
try
{
nwStream = receiver.GetStream();
sr = new StreamReader(nwStream);
this.getStatus();
string ret;
Console.WriteLine(sr.ReadLine());
input = "USER" + user + "\r\n";
outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray());
nwStream.Write(outbytes, 0, outbytes.Length);
this.getStatus();
Console.WriteLine(sr.ReadLine());
input = "PASS" + password + "\r\n";
outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray());
nwStream.Write(outbytes, 0, outbytes.Length);
this.getStatus();
Console.WriteLine(sr.ReadLine());
MessageBox.Show("登陆成功");
//listView1.Items.Clear();
input = "STAT" + "\r\n";
// if(nwStream.CanWrite)
//{
outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray());
nwStream.Write(outbytes, 0, outbytes.Length);
textBox10.Text = sr.ReadLine();
// }
// else
// {
// MessageBox.Show("无法写入数据");
// }
}
catch (InvalidOperationException ex)
{
Console.WriteLine("登陆失败");
}
}
console的信息
The thread 0x68e0 has exited with code 0 (0x0).
'sendandreceive.vshost.exe' (CLR v4.0.30319: sendandreceive.vshost.exe): Loaded 'D:\engineer program(course design)\sendandreceive\sendandreceive\bin\Debug\sendandreceive.exe'. Symbols loaded.
'sendandreceive.vshost.exe' (CLR v4.0.30319: sendandreceive.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'sendandreceive.vshost.exe' (CLR v4.0.30319: sendandreceive.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.resources\v4.0_4.0.0.0_zh-Hans_b77a5c561934e089\System.resources.dll'. Module was built without symbols.
The program '[22668] sendandreceive.vshost.exe' has exited with code -1 (0xffffffff).