Summary description for Form1.
Esempio n. 1
0
 OnRemovePeer
 (
     PeerData peer
 )
 {
     comboBox1.Items.Remove(peer);
 }
Esempio n. 2
0
        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;
                }
            }
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        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();
            }
        }
Esempio n. 5
0
        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");
            }
        }
Esempio n. 6
0
        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;
        }
Esempio n. 7
0
        OnResolveAddress
        (
            System.Net.IPAddress address
        )
        {
            resolver.Dispose();

            PeerData peer = (PeerData)comboBox1.SelectedItem;

            peer.Address = address;
        }
Esempio n. 8
0
        OnAddPeer
        (
            PeerData peer
        )
        {
            comboBox1.Items.Add(peer);

            if (comboBox1.Items.Count == 1)
            {
                comboBox1.SelectedIndex = 0;
            }
        }
Esempio n. 9
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;
            }
        }
Esempio n. 10
0
        //
        // 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();
            }
        }
Esempio n. 11
0
        //
        // 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();
            }
        }
Esempio n. 12
0
        //
        // 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 = "";
        }
Esempio n. 13
0
        //
        // 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 = "";
        }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
        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();
            }
        }
Esempio n. 16
0
        //
        // 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);
        }
Esempio n. 17
0
        //
        // 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");
            }
        }
Esempio n. 18
0
        //
        // 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);
        }
Esempio n. 19
0
        //
        // 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;
            }
        }
Esempio n. 20
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;

                }

            }
        }