UDP receive with parameters for thread

Source: Internet
Author: User

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); Accepted IP address and port number
//}
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.l ength==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
{
If the message is received, OK to close the switch
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 ("Not yet sent to PLC data!");
}

}
}


}

}

}

}
catch (Exception ex)
{
MessageBox.Show (ex. Message, "System prompt! ");
}
}

UDP receive with parameters for thread

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.