首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

"远程主机强迫关闭了一个现有的连接"怎样修改可以避免这个错误,请看上面

2013-01-05 
远程主机强迫关闭了一个现有的连接,怎样修改可以避免这个异常,请看下面using System using System.Comp

"远程主机强迫关闭了一个现有的连接",怎样修改可以避免这个异常,请看下面
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"); } 
            } 
        
        }    
    } 


[解决办法]
= =! 你客户端没连上呢吧,主要得看客户端的代码
[解决办法]
是不是服务器端监听程序关闭了 或者是客户端没有连接上服务器端

热点排行