c sharp UdpClient类
也可以直接使用System.Net下的UdpClient进行通信
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
using System.Net;
class Receive
{
public static void ReceivedData(int port)
{
UdpClient client = new UdpClient(port);
while (true)
{
IPEndPoint anyIP = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port);
byte[] data = client.Receive(ref anyIP);
string text = Encoding.UTF8.GetString(data);
//Console.WriteLine("text " + text);
float data_t = Convert.ToSingle(text);
Console.WriteLine("data_t " + data_t);
//text.Toflo
}
}
public static void Main()
{
ReceivedData(5064);
}
}
}
每天快乐敲代码,快乐生活