OnRemovePeer ( PeerData peer ) { comboBox1.Items.Remove(peer); }
ServiceFound ( DNSSDService sref, DNSSDFlags flags, uint ifIndex, String serviceName, String regType, String domain ) { if (serviceName != m_name) { PeerData peer = new PeerData(); peer.InterfaceIndex = ifIndex; peer.Name = serviceName; peer.Type = regType; peer.Domain = domain; peer.Address = null; comboBox1.Items.Add(peer); if (comboBox1.Items.Count == 1) { comboBox1.SelectedIndex = 0; } } }
Equals(object other) { bool result = false; if (other != null) { if ((object)this == other) { result = true; } else if (other is PeerData) { PeerData otherPeerData = (PeerData)other; result = (this.Name == otherPeerData.Name); } } return(result); }
ServiceResolved ( DNSSDService sref, DNSSDFlags flags, uint ifIndex, String fullName, String hostName, ushort port, TXTRecord txtRecord ) { m_resolver.Stop(); m_resolver = null; PeerData peer = (PeerData)comboBox1.SelectedItem; peer.Port = port; try { m_resolver = m_service.QueryRecord(0, ifIndex, hostName, DNSSDRRType.kDNSSDType_A, DNSSDRRClass.kDNSSDClass_IN, m_eventManager); } catch { MessageBox.Show("QueryRecord Failed", "Error"); Application.Exit(); } }
OnBrowseReply ( ServiceRef sdRef, ServiceFlags flags, int interfaceIndex, ErrorCode errorCode, String name, String type, String domain) { if (errorCode == ErrorCode.NoError) { PeerData peer = new PeerData(); peer.InterfaceIndex = interfaceIndex; peer.Name = name; peer.Type = type; peer.Domain = domain; peer.Address = null; if ((flags & ServiceFlags.Add) != 0) { Invoke(addPeerCallback, new Object[] { peer }); } else if ((flags == 0) || ((flags & ServiceFlags.MoreComing) != 0)) { Invoke(removePeerCallback, new Object[] { peer }); } } else { MessageBox.Show("OnBrowseReply returned an error code " + errorCode, "Error"); } }
QueryAnswered ( DNSSDService service, DNSSDFlags flags, uint ifIndex, String fullName, DNSSDRRType rrtype, DNSSDRRClass rrclass, Object rdata, uint ttl ) { // // Stop the resolve to reduce the burden on the network // m_resolver.Stop(); m_resolver = null; PeerData peer = (PeerData)comboBox1.SelectedItem; uint bits = BitConverter.ToUInt32((Byte[])rdata, 0); System.Net.IPAddress address = new System.Net.IPAddress(bits); peer.Address = address; }
OnResolveAddress ( System.Net.IPAddress address ) { resolver.Dispose(); PeerData peer = (PeerData)comboBox1.SelectedItem; peer.Address = address; }
OnAddPeer ( PeerData peer ) { comboBox1.Items.Add(peer); if (comboBox1.Items.Count == 1) { comboBox1.SelectedIndex = 0; } }
// // called when typing in message box // private void textBox2_TextChanged(object sender, System.EventArgs e) { PeerData peer = (PeerData)comboBox1.SelectedItem; if ((peer.Address != null) && (textBox2.Text.Length > 0)) { button1.Enabled = true; } else { button1.Enabled = false; } }
// // called when peer target changes // /// <summary> /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e) { PeerData peer = (PeerData)comboBox1.SelectedItem; try { resolver = DNSService.Resolve(0, 0, peer.Name, peer.Type, peer.Domain, new DNSService.ResolveReply(OnResolveReply)); } catch { MessageBox.Show("Unable to Resolve service", "Error"); Application.Exit(); } }
// // called when peer target changes // /// <summary> /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e) { PeerData peer = (PeerData)comboBox1.SelectedItem; try { m_resolver = m_service.Resolve(0, peer.InterfaceIndex, peer.Name, peer.Type, peer.Domain, m_eventManager); } catch { MessageBox.Show("Unable to Resolve service", "Error"); Application.Exit(); } }
// // send the message to a peer // private void button1_Click(object sender, System.EventArgs e) { PeerData peer = (PeerData)comboBox1.SelectedItem; String message = m_name + ": " + textBox2.Text; Byte[] bytes = Encoding.UTF8.GetBytes(message); IPEndPoint endPoint = new IPEndPoint(peer.Address, peer.Port); m_socket.SendTo(bytes, endPoint); richTextBox1.SelectionColor = Color.Black; richTextBox1.AppendText(textBox2.Text + "\n"); textBox2.Text = ""; }
// // send the message to a peer // private void button1_Click(object sender, System.EventArgs e) { PeerData peer = (PeerData)comboBox1.SelectedItem; String message = myName + ": " + textBox2.Text; Byte[] bytes = Encoding.UTF8.GetBytes(message); UdpClient udpSocket = new UdpClient(peer.Address.ToString(), peer.Port); udpSocket.Send(bytes, bytes.Length); richTextBox1.SelectionColor = Color.Black; richTextBox1.AppendText(textBox2.Text + "\n"); textBox2.Text = ""; }
ServiceLost ( DNSSDService sref, DNSSDFlags flags, uint ifIndex, String serviceName, String regType, String domain ) { PeerData peer = new PeerData(); peer.InterfaceIndex = ifIndex; peer.Name = serviceName; peer.Type = regType; peer.Domain = domain; peer.Address = null; comboBox1.Items.Remove(peer); }
OnResolveService ( ResolveData data ) { resolver.Dispose(); PeerData peer = (PeerData)comboBox1.SelectedItem; peer.Port = data.Port; try { resolver = DNSService.QueryRecord(0, 0, data.HostName, /* ns_t_a */ 1, /* ns_t_c */ 1, new DNSService.QueryRecordReply(OnQueryRecordReply)); } catch { MessageBox.Show("QueryRecord Failed", "Error"); Application.Exit(); } }
// // OnRemovePeer // // Called when DNSServices detects a P2P peer has left // the network // // This is called (indirectly) from OnBrowseReply() // private void OnRemovePeer( PeerData peer ) { comboBox1.Items.Remove(peer); }
// // OnBrowseReply // // Called by DNSServices core as a result of DNSService.Browse() // call // // This is called from a worker thread by DNSService core. // private void OnBrowseReply( ServiceRef sdRef, ServiceFlags flags, int interfaceIndex, ErrorCode errorCode, String name, String type, String domain) { if (errorCode == ErrorCode.NoError) { PeerData peer = new PeerData(); peer.InterfaceIndex = interfaceIndex; peer.Name = name; peer.Type = type; peer.Domain = domain; peer.Address = null; if ((flags & ServiceFlags.Add) != 0) { Invoke(addPeerCallback, new Object[]{peer}); } else if ((flags == 0) || ((flags & ServiceFlags.MoreComing) != 0)) { Invoke(removePeerCallback, new Object[]{peer}); } } else { MessageBox.Show("OnBrowseReply returned an error code " + errorCode, "Error"); } }
// // ServiceLost // // Called by DNSServices core as a result of a Browse call // public void ServiceLost( DNSSDService sref, DNSSDFlags flags, uint ifIndex, String serviceName, String regType, String domain ) { PeerData peer = new PeerData(); peer.InterfaceIndex = ifIndex; peer.Name = serviceName; peer.Type = regType; peer.Domain = domain; peer.Address = null; comboBox1.Items.Remove(peer); }
// // OnAddPeer // // Called when DNSServices detects a new P2P Chat peer has // joined. // // This is called (indirectly) from OnBrowseReply() // private void OnAddPeer( PeerData peer ) { comboBox1.Items.Add(peer); if (comboBox1.Items.Count == 1) { comboBox1.SelectedIndex = 0; } }
// // ServiceFound // // Called by DNSServices core as a result of a Browse call // public void ServiceFound( DNSSDService sref, DNSSDFlags flags, uint ifIndex, String serviceName, String regType, String domain ) { if (serviceName != m_name) { PeerData peer = new PeerData(); peer.InterfaceIndex = ifIndex; peer.Name = serviceName; peer.Type = regType; peer.Domain = domain; peer.Address = null; comboBox1.Items.Add(peer); if (comboBox1.Items.Count == 1) { comboBox1.SelectedIndex = 0; } } }