日期:2014-05-17  浏览次数:20990 次

C#UDP,从移动端发送到电脑端接收后,及时显示图片
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.IO;
using System.Xml;

namespace UDPTest2_2
{
    public partial class Form1 : Form
    {
        Thread thread;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Form1.CheckForIllegalCrossThreadCalls = false;      //不可在多线程中使用
            thread = new Thread(new ThreadStart(ReceiveDataFromUDPClient));     //调用类
            thread.IsBackground = true;     //是否结束线程
            thread.Start();     //开始运行
        }
        public void ReceiveDataFromUDPClient()
        {
            try{
            while (true)
            {
                XmlDocument doc = new XmlDocument();        //调用XML
                doc.Load("XMLFile1.xml");       //指定Xml文件路径
                XmlNode node;              //读取节点
                node = doc.SelectSingleNode("//Config/SvcInfo/SvcPort/text()");     //读取XML节点
                string svcPort = node.Value;        //定义节点数值
                if (svcPort.Length > 0)            //当对象>0时,执行程序
                {
                    UdpClient udpClient = new UdpClient(int.Parse(svcPort));     //实例化一个对象
       &n