"远程主机强迫关闭了一个现有的连接",怎样修改可以避免这个异常,请看下面
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.Windows.Forms;
using System.Threading;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
IPEndPoint server = null;
UdpClient uc = null;
public Form1()
{
InitializeComponent();
}
Thread thread1 = null;
private void Form1_Load(object sender, EventArgs e)
{
try
{
IPEndPoint iep = new IPEndPoint(IPAddress.Any, 1000);
IPAddress address = IPAddress.Parse("127.0.0.1");
byte[] a=new byte[]{1,11};
uc = new UdpClient();
server = new IPEndPoint(address, 1000);
uc.Send(a,a.Length,server);
thread1 = new Thread(jieshou);
thread1.Start();
}
catch
{
MessageBox.Show("sdf");
}
}
public void jieshou()
{
while (true)
{
try
{
byte[] Data = uc.Receive(ref server); //将获取的远程消息转换成二进制
//throw new Exception("sdf");
}
catch
{ MessageBox.Show("d"); }
}
}
}
}
------解决方案--------------------= =! 你客户端没连上呢吧,主要得看客户端的代码
------解决方案--------------------是不是服务器端监听程序关闭了 或者是客户端没有连接上服务器端