// // called when the type field changes // private void typeBox_SelectedIndexChanged(object sender, System.EventArgs e) { browseList.Items.Clear(); if (browser != null) { browser.Dispose(); } nameField.Text = ""; typeField.Text = ""; domainField.Text = ""; hostField.Text = ""; portField.Text = ""; serviceTextField.Items.Clear(); try { browser = DNSService.Browse(0, 0, typeBox.SelectedItem.ToString(), null, new DNSService.BrowseReply(OnBrowseReply)); } catch { MessageBox.Show("Browse Failed", "Error"); Application.Exit(); } }
private void Form1_Load(object sender, EventArgs e) { IPEndPoint localEP = new IPEndPoint(System.Net.IPAddress.Any, 0); // // create the socket and bind to INADDR_ANY // socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); socket.Bind(localEP); localEP = (IPEndPoint)socket.LocalEndPoint; // // start asynchronous read // SocketStateObject so = new SocketStateObject(socket); socket.BeginReceive(so.m_buffer, 0, SocketStateObject.BUFFER_SIZE, 0, new AsyncCallback(this.OnReadSocket), so); try { // // start the register and browse operations // registrar = DNSService.Register(0, 0, System.Environment.UserName, "_p2pchat._udp", null, null, localEP.Port, null, new DNSService.RegisterReply(OnRegisterReply)); browser = DNSService.Browse(0, 0, "_p2pchat._udp", null, new DNSService.BrowseReply(OnBrowseReply)); } catch { MessageBox.Show("DNSServices Not Available", "Error"); Application.Exit(); } }