Socket is already connected.

Oct 17, 2014 at 9:00 AM
Edited Oct 17, 2014 at 11:44 AM
I'm building for Xamarin Mac and iOS.
Simple A recorde query returns null DnsMessage.

i found that an exception "Socket is already connected" was raised in DnsClientBase.QueryByUdp() .

The following fix works anyway.

DnsClientBase.cs:
private byte[] QueryByUdp(DnsClientEndpointInfo endpointInfo, byte[] messageData, int messageLength, out IPAddress responderAddress)
{
  ....
                    if( udpClient.Connected )
                        udpClient.Send(messageData);
                    else 
                        udpClient.SendTo(messageData, messageLength, SocketFlags.None, serverEndpoint);
Also for async version:
        private void UdpBeginSend<TMessage>(DnsClientAsyncState<TMessage> state)
            where TMessage : DnsMessageBase, new()
        {
                 ....
                IAsyncResult asyncResult;
                if( state.UdpClient.Connected == true){
                    asyncResult = state.UdpClient.BeginSend(
                        state.QueryData, 0, state.QueryLength, 
                        SocketFlags.None,  UdpSendCompleted<TMessage>, state);
                }else {
                    asyncResult = state.UdpClient.BeginSendTo(
                        state.QueryData, 0, state.QueryLength, 
                        SocketFlags.None, state.UdpEndpoint, UdpSendCompleted<TMessage>, state);
                }
Am I missing something to configure or other ?