• 线程带参数的Udp接收


    //work wk = new work(ReadUdpDate);
    ParameterizedThreadStart parmThre = new ParameterizedThreadStart(ReadUdpDate);
    Thread read = new Thread(parmThre);
    read.Start(ipAddress);  

    private void ReadUdpDate(object IP)
    {
    string message = "";
    try
    {


    while (true)
    {
    //if (remoteIpep==null)
    //{
    // remoteIpep = new IPEndPoint(IPAddress.Parse("192.168.6.32"), 26); // 接受的IP地址和端口号
    //}
    if (ReadUdpClient==null)
    {
    return;
    }
    int buff = ReadUdpClient.Client.Available;
    if (buff > 0)
    {

    byte[] bytRecv = ReadUdpClient.Receive(ref remoteIpep);
    if (bytRecv.Length > 0)
    {
    message = Encoding.UTF8.GetString(bytRecv, 0, bytRecv.Length);
    if (bytRecv.Length==35)
    {
    string sch = message.Substring(0, 20);
    sch = sch.Substring(0, 10);
    int countNum = int.Parse(message.Substring(20, 2));
    string jiIP = remoteIpep.Address.ToString();

    if (qzz.select_diepian(sch, jiIP))
    {
    qzz.update_diepian(sch, countNum, jiIP);
    }
    else
    {
    qzz.insert_diepian(sch, countNum, jiIP);
    }
    }
    else
    {
    //如果接收到的信息时OK 关闭开关
    if (message.ToUpper() == "OK")///&& IP == remoteIpep.Address.ToString())
    {

    }
    else if (message.ToUpper() == "NG")/// && IP == remoteIpep.Address.ToString())
    {
    if (sendbytes!=null)
    {
    sendUdpClient.Send(sendbytes, sendbytes.Length, remoteIpep);
    }
    else
    {
    //MessageBox.Show("还未发送给PLC数据!");
    }

    }
    }


    }

    }

    }

    }
    catch (Exception ex)
    {
    MessageBox.Show( ex.Message, "系统提示!");
    }
    }

  • 相关阅读:
    网页布局
    Block Formatting Context
    SEO初识
    新的一个月,就这么不知不觉的来临了
    Js结束,项目进行中
    JS学习中....
    ws快捷键
    Html的学习以及webstorm的使用
    从事前端开发应该了解的CSS原理
    jQuery动画
  • 原文地址:https://www.cnblogs.com/VictorBlog/p/5193123.html
Copyright © 2020-2023  润新知