日期:2014-05-19  浏览次数:20849 次

一个UDP通讯的小程序,各位帮我看看。
下面是我做的一个UDP通讯小程序,
开了两个线程,一个用于接收,一个用于发送,
用了两个UDPClient,一个用于发送,一个用于接收。
为什么单机运行两个程序会出错?
using   System;
using   System.Collections.Generic;
using   System.ComponentModel;
using   System.Data;
using   System.Drawing;
using   System.Text;
using   System.Windows.Forms;
using   System.Net;
using   System.Net.Sockets;
using   System.Threading;

namespace   UDP多线程
{
        public   partial   class   Form1   :   Form
        {
                public   Form1()
                {
                        InitializeComponent();                      
                }


                public   UdpClient   receiveUdp;
                public   IPEndPoint   receivePoint;
                public   int   LocalPort=8080;                                     //本地端口

                public   UdpClient   sendUdp;
                public   IPEndPoint   remotePoint;                    
                public   int   RemotPort;                                   //远程通讯端口      
               
                public   string   sendText;                               //发送命令文本
               
                public   Thread   recvThread;                         //定义接收线程
                public   Thread   checkSendThread;               //定义检测发送线程

               
               
               

                //接收
                public   void   receive()
                {
                        receiveUdp   =   new   UdpClient(LocalPort);                        
                        IPAddress   myip   =   IPAddress.Parse( "127.0.0.1 ");
                        receivePoint   =   new   IPEndPoint(myip,   LocalPort);