线程带参数的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, "系统提示!");
}
}

上一篇:JavaScript页面刷新与弹出窗口问题的解决方法


下一篇:修改Eclipse jdk环境