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.