1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using System;
- using System.Threading;
- using ToolsClassLibrary;
- namespace IntelligentControlForsx.Code
- {
- /// <summary>
- ///
- /// </summary>
- public static class UdpMassage
- {
- static UdpHelper udp = new UdpHelper();
- static Thread threadServer;
- public static void UdpSocketStart()
- {
- udp.ClientBind();
- threadServer = new Thread(recMsg);
- threadServer.IsBackground = true;
- threadServer.Start();
- }
- static void recMsg()
- {
- while (true)
- {
- byte[] data;
- try
- {
- data = udp.Receive();
- }
- catch (Exception ex)
- {
- Console.WriteLine(string.Format("出现异常:{0}", ex.Message));
- continue;
- }
- object dic = JsonHelper.DeSerializeBinary(data);
- SocketData<double> udpdata = (SocketData<double>)dic;
- foreach (var key in udpdata.FileData.Keys)
- {
- string sid = key;
- double sval =udpdata.FileData[key];
- CommunalTarget.UdpDoubleMemory.AddorUpdate(sid, sval);
- }
- }
- }
- }
- }
|