0

I have a client program written in c++ that sends via UDP a structure of values:

struct myData
{
    double n1;
    double n2;
};

myData* sendBuffer = (myData*)malloc(sizeof(mydata)); 
memcpy(sendBuffer, &mydata, sizeof(mydata));

However over on the server side (in c#, winforms), I use something like:

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);
}

I understand that in C++, I could simply call memcpy() on the server side to obtain the structure of values automatically, but is there a way to do it in C#?

John Tan
  • 1,331
  • 1
  • 19
  • 35

0 Answers0