日期:2014-05-17 浏览次数:20941 次
static void Main(string[] args)
{
IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName());
IPEndPoint endPoint = new IPEndPoint(hostEntry.AddressList[0], 60000);
Socket s = new Socket(endPoint.Address.AddressFamily,SocketType.Dgram,ProtocolType.Udp);
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
EndPoint senderRemote = (EndPoint)sender;
s.Bind(endPoint);
byte[] msg = new Byte[256];
Console.ForegroundColor = ConsoleColor.Red; //设置字体颜色为红色
Console.WriteLine("Waiting...");
LogMessage message = new LogMessage();
while(true)
{
s.ReceiveFrom(msg, ref senderRemote);
string deviceID = Convert.ToString(msg[5], 16);
//string rt = byteToHexStr(msg);
string iPstr = senderRemote.ToString();
ipStringSplit = iPstr.Split(':') ;
Console.ForegroundColor = ConsoleColor.Green;
message.DeviceID = deviceID;
message.DeviceIP = ipStringSplit[0];
message.DevicePort =ipStringSplit[1];
log.Info(message);
}
}