Socket is already connected.

Oct 17, 2014 at 8:00 AM
Edited Oct 17, 2014 at 10: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.

private byte[] QueryByUdp(DnsClientEndpointInfo endpointInfo, byte[] messageData, int messageLength, out IPAddress responderAddress)
                    if( udpClient.Connected )
                        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 ?