Forum Xamarin.iOS
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to send and receive on the same port with UDP?

I am trying to do a udp communication, and on Android, this line will work, but not with iOS.. is there a specific thing I need to do before it can be achieved?

private static void SendAndReceive()
  IPEndPoint ep1 = new IPEndPoint(IPAddress.Any, 1234);
    UdpClient receiveClient = new UdpClient();
    receiveClient.ExclusiveAddressUse = false;
    receiveClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
    byte[] buffer = receiveClient.Receive(ref ep1);

  UdpClient sendClient = new UdpClient();
  sendClient.ExclusiveAddressUse = false;
  sendClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
  IPEndPoint ep2 = new IPEndPoint(IPAddress.Parse("X.Y.Z.W"), 1234);
  sendClient.Send(new byte[] { ... }, sizeOfBuffer, ep2);

Sign In or Register to comment.