Пример #1
0
 public AsyncReaderState(DnsTcpClient client, IAsyncResult result)
 {
     Client = client;
     Result = result;
 }
Пример #2
0
    private void buttonClientSend_Click(object sender, EventArgs e)
    {
      string errorMessage;
      IPAddress serverAddr;
      Cursor = Cursors.WaitCursor;
      buttonClientSend.Enabled = false;

      if (!ValidateServerText(textBoxClientServer.Text, out errorMessage))
      {
        errorProvider1.SetError(textBoxClientServer, errorMessage);
        return;
      }
      try
      {
        // resolve server name by System.Net.Dns
        serverAddr = System.Net.Dns.GetHostAddresses(textBoxClientServer.Text.Trim()).First();
      }
      catch (SocketException)
      {
        errorProvider1.SetError(textBoxClientServer, "Server name cannot be resolved.");
        return;
      }

      try
      {
        IDnsClient client;
        if (radioButtonClientTCP.Checked)
          client = new DnsTcpClient();
        else
          client = new DnsUdpClient();

        Request request = new Request(
          (ushort)DateTime.Now.Ticks,
          checkBoxClientRD.Checked,
          (OPCODE)Enum.Parse(typeof(OPCODE), comboBoxClientOPCODE.SelectedValue.ToString()),
          new Question(
            textBoxClientQNAME.Text.Trim(),
            (QTYPE)Enum.Parse(typeof(QTYPE), comboBoxClientQTYPE.SelectedValue.ToString()),
            (QCLASS)Enum.Parse(typeof(QCLASS), comboBoxClientQCLASS.SelectedValue.ToString())));


        labelClientResponse.Text = String.Empty;
        textBoxClientResponse.Text = String.Empty;

        client.Connect(serverAddr);
        client.BeginProcess(request, new AsyncCallback(OnClientResponseReceived),
          new ClientAsyncState { Client = client, Request = request, Server = serverAddr });

        //try
        //{
        //  client.Connect(serverAddr);
        //  DnsClient.Response response = client.LookUp(request);
        //  labelClientResponse.Text = String.Format("{0}: {1} from [{2}] in {3}ms",
        //    (response.Header.AA ? "Authoritative Response" : "Non-Authoritative Response"),
        //    response.Header.RCODE.ToString(),
        //    serverAddr.ToString(),
        //    response.Timestamp.Subtract(request.Timestamp).TotalMilliseconds);
        //  StringBuilder result = new StringBuilder();
        //  RenderResponse(response, result);
        //  textBoxClientResponse.Text = result.ToString();
        //}
        //finally
        //{
        //  Cursor = Cursors.Default;
        //  buttonClientSend.Enabled = true;
        //}


      }
      catch (Exception ex)
      {
        MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
      }
    }
Пример #3
0
 public AsyncReaderState(DnsTcpClient client, IAsyncResult result)
 {
     Client = client;
     Result = result;
 }