我有一个用c ++编写的客户端程序,它通过UDP发送一个值结构:
struct myData
{
double n1;
double n2;
};
myData* sendBuffer = (myData*)malloc(sizeof(mydata));
memcpy(sendBuffer, &mydata, sizeof(mydata));
然而,在服务器端(在c#,winforms中),我使用的是:
IPAddress address = IPAddress.Parse("127.0.0.1");
IPEndPoint ipep = new IPEndPoint(address, 8888);
UdpClient newsock = new UdpClient(ipep);
while (true)
{
var received = newsock.Receive(ref ipep);
}
据我所知,在C ++中,我可以简单地在服务器端调用memcpy()
来自动获取值的结构,但有没有办法在C#中实现呢?