示例#1
0
        // 接收回调函数
        private void ReceiveCallback(IAsyncResult iar)
        {
            UdpState udpReceiveState = iar.AsyncState as UdpState;

            if (iar.IsCompleted)
            {
                Byte[] receiveBytes = udpReceiveState.udpClient.EndReceive(iar, ref udpReceiveState.ipEndPoint);

                Thread th = new Thread(new ParameterizedThreadStart(Show));
                th.Start(receiveBytes);

                //Thread.Sleep(200);
                receiveDone.Set();
            }
        }
示例#2
0
        bool flag = true;  //ReceiveMeg函数开始标记



        public MainForm()
        {
            InitializeComponent();
            messageCallback                    = new messageListCallback(setMessage); //绑定信息提示事件函数
            userCallback                      += userListShow;                        //z这边写出函数名以后,可以自动生成相应的函数(函数参数与相应的委托声明相同)
            userOfflineCallback               += userOffline;
            clientConnect                      = new ClientConnectTcp();
            clientConnect.ServerConnected     += clientConnect_ServerConnected;
            clientConnect.ServerConnectFailed += clientConnect_ServerConnectFailed;
            clientConnect.MessageReceived     += clientConnect_MessageReceived;
            clientConnect.ServerLost          += clientConnect_ServerLost;
            imgList = this.imageList1;
            // 本机节点
            ipEndPoint = new IPEndPoint(IPAddress.Any, listenPort);
            // 远程节点
            //remoteEP = new IPEndPoint(IPAddress.Parse("172.26.162.212"), remotePort);
            // 实例化
            udpReceive = new UdpClient(ipEndPoint);
            // 实例化udpReceiveState
            udpReceiveState            = new UdpState();
            udpReceiveState.udpClient  = udpReceive;
            udpReceiveState.ipEndPoint = ipEndPoint;
        }